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 表单验证方法(实用)
Apr 28 Javascript
学习ExtJS(二) Button常用方法
Oct 07 Javascript
原生js 秒表实现代码
Jul 24 Javascript
JavaScript中“基本类型”之争小结
Jan 03 Javascript
js判断鼠标同时离开两个div的思路及代码
May 31 Javascript
代码触发js事件(click、change)示例应用
Dec 13 Javascript
深入理解Javascript里的依赖注入
Mar 19 Javascript
Javascript将字符串日期格式化为yyyy-mm-dd的方法
Oct 27 Javascript
AngularJS中transclude用法详解
Nov 03 Javascript
JavaScript中的this陷阱的最全收集并整理(没有之一)
Feb 21 Javascript
详解如何在react中搭建d3力导向图
Jan 12 Javascript
微信小程序入门之指南针
Oct 22 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输出表格的实现代码(修正版)
2010/12/29 PHP
php中unlink()、mkdir()、rmdir()等方法的使用介绍
2012/12/21 PHP
无刷新动态加载数据 滚动条加载适合评论等页面
2013/10/16 PHP
使用图灵api创建微信聊天机器人
2015/07/23 PHP
JavaScript获取FCK编辑器信息的具体方法
2013/07/12 Javascript
javascript仿php的print_r函数输出json数据
2013/09/13 Javascript
js实现点击添加一个input节点
2014/12/05 Javascript
用js代码和插件实现wordpress雪花飘落效果的四种方法
2014/12/15 Javascript
jQuery操作表单常用控件方法小结
2015/03/23 Javascript
JS 作用域与作用域链详解
2015/04/07 Javascript
AngularJS中实现显示或隐藏动画效果的方式总结
2015/12/31 Javascript
jQuery解析与处理服务器端返回xml格式数据的方法详解
2016/07/04 Javascript
总结JavaScript的正则与其他语言的不同之处
2016/08/25 Javascript
基于vue.js实现图片轮播效果
2016/12/01 Javascript
js实现移动端微信页面禁止字体放大
2017/02/16 Javascript
微信小程序 检查接口状态实例详解
2017/06/23 Javascript
Javascript实现base64的加密解密方法示例
2017/06/27 Javascript
微信小程序request请求后台接口php的实例详解
2017/09/20 Javascript
代码详解javascript模块加载器
2018/03/04 Javascript
微信小程序开发之自定义tabBar的实现
2018/09/06 Javascript
使用JavaScript和MQTT开发物联网应用示例解析
2020/08/07 Javascript
Python中运行并行任务技巧
2015/02/26 Python
Python实现的批量修改文件后缀名操作示例
2018/12/07 Python
PyCharm无法识别PyQt5的2种解决方法,ModuleNotFoundError: No module named 'pyqt5'
2020/02/17 Python
python如何调用字典的key
2020/05/25 Python
HTML5之多线程(Web Worker)
2019/01/02 HTML / CSS
床上用品全球在线购物:BeddingInn
2016/12/18 全球购物
墨尔本最受欢迎的复古风格品牌:Princess Highway
2018/12/21 全球购物
主管职责范文
2013/11/09 职场文书
演讲稿怎么写才完美
2014/01/02 职场文书
打架检讨书800字
2014/01/10 职场文书
领导班子四风问题对照检查材料
2014/09/27 职场文书
2014年个人工作总结报告
2014/11/27 职场文书
小学数学教师研修日志
2015/11/13 职场文书
《地震中的父与子》教学反思
2016/02/16 职场文书
通过T-SQL语句创建游标与实现数据库加解密功能
2022/03/16 SQL Server