Javascript下判断是否为闰年的Datetime包


Posted in Javascript onOctober 26, 2010

来看看源码:

/** 
* jscript.datetime package 
* This package contains utility functions for working with dates and times. 
*/ 
/*命名空间*/ 
if (typeof jscript == 'undefined') { 
jscript = function() { } 
} jscript.datetime = function() { } 
/** 
* This function will return the number of days in a given month and year, 
* taking leap years into account.(这个函数返回所给某年、某月的天数,并且考虑了闰年的情况) 
* 
* @param inMonth The month, where January = 1 and December = 12. 
* @param inYear The year to check the month in. 
* @return The number of days in the specified month and year. 
*/ 
jscript.datetime.getNumberDaysInMonth = function(inMonth, inYear) { 
inMonth = inMonth - 1; 
var leap_year = this.isLeapYear(inYear); 
if (leap_year) { 
leap_year = 1; 
} else { 
leap_year = 0; 
} 
/*4, 6, 9, 11 月为 30 天,注意上面的 inMonth = inMonth - 1*/ 
if (inMonth == 3 || inMonth == 5 || inMonth == 8 || inMonth == 10) { 
return 30; 
} else if (inMonth == 1) {/*2 月为 28 或者 29 天,视是否为闰年而定*/ 
return 28 + leap_year; 
} else {/*其它月则为 31 天*/ 
return 31; 
} 
} // End getNumberDaysInMonth(). 

/** 
* This function will determine if a given year is a leap year. 
*(这个函数用来确定是否为闰年) 
* @param inYear The year to check. 
* @return True if inYear is a leap year, false if not. 
*/ 
jscript.datetime.isLeapYear = function(inYear) { 
if ((inYear % 4 == 0 && !(inYear % 100 == 0)) || inYear % 400 == 0) { 
return true; 
} else { 
return false; 
} 
} // End isLeapYear().
Javascript 相关文章推荐
js继承的实现代码
Aug 05 Javascript
js图片自动切换效果处理代码
May 07 Javascript
jQuery中Ajax的get、post等方法详解
Jan 20 Javascript
js淡入淡出的图片轮播效果代码分享
Aug 24 Javascript
JS基于面向对象实现的拖拽库实例
Sep 24 Javascript
Javascript json object 与string 相互转换的简单实现
Sep 27 Javascript
HTML的select控件美化
Mar 27 Javascript
js 将canvas生成图片保存,或直接保存一张图片的实现方法
Jan 02 Javascript
如何理解Vue的v-model指令的使用方法
Jul 19 Javascript
jQuery实现飞机大战小游戏
Jul 05 jQuery
解决Element中el-date-picker组件不回填的情况
Nov 07 Javascript
微信小程序scroll-view不能左右滑动问题的解决方法
Jul 09 Javascript
基于jquery的给文章加入关键字链接
Oct 26 #Javascript
EasyUi tabs的高度与宽度根据IE窗口的变化自适应代码
Oct 26 #Javascript
自写的一个jQuery圆角插件
Oct 26 #Javascript
jQuery获取地址栏参数插件(模仿C#)
Oct 26 #Javascript
自制轻量级仿jQuery.boxy对话框插件代码
Oct 26 #Javascript
jquery ui resizable bug解决方法
Oct 26 #Javascript
HTML Dom与Css控制方法
Oct 25 #Javascript
You might like
PHP Squid中可缓存的动态网页设计
2008/09/17 PHP
php笔记之:php数组相关函数的使用
2013/04/26 PHP
Yii框架Session与Cookie使用方法示例
2019/10/14 PHP
JS Excel读取和写入操作(模板操作)实现代码
2010/04/11 Javascript
jquery 插件学习(三)
2012/08/06 Javascript
js修改地址栏URL参数解决url参数问题
2012/12/15 Javascript
JS 删除字符串最后一个字符的实现代码
2014/02/20 Javascript
常规表格多表头查询示例
2014/02/21 Javascript
JS和函数式语言的三特性
2014/03/05 Javascript
jQuery截取指定长度字符串代码
2014/08/21 Javascript
node.js中RPC(远程过程调用)的实现原理介绍
2014/12/05 Javascript
js实现浏览器窗口大小被改变时触发事件的方法
2015/02/02 Javascript
transport.js和jquery冲突问题的解决方法
2015/02/10 Javascript
JavaScript和HTML DOM的区别与联系及Javascript和DOM的关系
2015/11/15 Javascript
基于JavaScript的操作系统你听说过吗?
2016/01/28 Javascript
JS简单实现数组去重的方法示例
2017/03/27 Javascript
javascript+jQuery实现360开机时间显示效果
2017/11/03 jQuery
基于vue-resource jsonp跨域问题的解决方法
2018/02/03 Javascript
解决低版本的浏览器不支持es6的import问题
2018/03/09 Javascript
js实现上传图片并显示图片名称
2019/12/18 Javascript
记一次用ts+vuecli4重构项目的实现
2020/05/21 Javascript
Python使用redis pool的一种单例实现方式
2016/04/16 Python
关于Django显示时间你应该知道的一些问题
2017/12/25 Python
pycharm 对代码做静态检查操作
2020/06/09 Python
Python如何读取、写入JSON数据
2020/07/28 Python
python 读取、写入txt文件的示例
2020/09/27 Python
HTML5+CSS3绘制锯齿状的矩形
2016/03/01 HTML / CSS
canvas生成带二维码海报的踩坑记录
2019/09/11 HTML / CSS
美国女性服饰销售网站:Nasty Gal(坏女孩)
2016/07/26 全球购物
End Clothing美国站:英国男士潮牌商城
2018/04/20 全球购物
护士长竞聘书
2014/03/31 职场文书
建筑管理专业求职信
2014/07/28 职场文书
2014年连锁店圣诞节活动方案
2014/12/09 职场文书
数学教师求职信范文
2015/03/20 职场文书
Spring整合Mybatis的全过程
2021/06/28 Java/Android
如何在python中实现ECDSA你知道吗
2021/11/23 Python