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四舍五入数学函数round使用实例
May 09 Javascript
JavaScript中的this机制
Jan 30 Javascript
javascript轻量级库createjs使用Easel实现拖拽效果
Feb 19 Javascript
Bootstrap每天必学之导航组件
Apr 25 Javascript
js获取html的span标签的值方法(超简单)
Jul 26 Javascript
Angularjs的Controller间通信机制实例分析
Nov 07 Javascript
jQuery中checkbox反复调用attr('checked', true/false)只有第一次生效的解决方法
Nov 16 Javascript
jquery实现超简单的瀑布流布局【推荐】
Mar 08 Javascript
jquery实现的简单轮播图功能【适合新手】
Aug 17 jQuery
小程序实现列表多个批量倒计时
Jan 29 Javascript
详解微信小程序之一键复制到剪切板
Apr 24 Javascript
Vue实现简单计算器案例
Feb 25 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无限级分类实现方法分析
2016/10/19 PHP
Ajax+PHP实现的删除数据功能示例
2019/02/12 PHP
PHP rmdir()函数的用法总结
2019/07/02 PHP
静态的动态续篇之来点XML
2006/08/15 Javascript
CSS JavaScript 实现菜单功能 改进版
2008/12/09 Javascript
让FireFox支持innerText的实现代码
2009/12/01 Javascript
JS模拟Dialog弹出浮动框效果代码
2015/10/16 Javascript
浅析Bootstrap缩略图组件与警示框组件
2016/04/29 Javascript
简单实现js拖拽效果
2017/07/25 Javascript
微信小程序之侧边栏滑动实现过程解析(附完整源码)
2019/08/23 Javascript
vue中利用iscroll.js解决pc端滚动问题
2020/02/15 Javascript
[53:15]Mineski vs iG 2018国际邀请赛小组赛BO2 第二场 8.16
2018/08/17 DOTA
[00:16]热血竞技场
2019/03/06 DOTA
Python时间获取及转换知识汇总
2017/01/11 Python
Python实现字符串格式化输出的方法详解
2017/09/20 Python
基于Python中求和函数sum的用法详解
2018/06/28 Python
python 定时器,实现每天凌晨3点执行的方法
2019/02/20 Python
python在回调函数中获取返回值的方法
2019/02/22 Python
Python实现定时执行任务的三种方式简单示例
2019/03/30 Python
Python3加密解密库Crypto的RSA加解密和签名/验签实现方法实例
2020/02/11 Python
在pycharm中关掉ipython console/PyDev操作
2020/06/09 Python
美国校园市场:OCM
2017/06/08 全球购物
西班牙英格列斯百货法国官网:El Corte Inglés法国
2017/07/09 全球购物
Perfumetrader荷兰:香水、化妆品和护肤品在线商店
2017/09/15 全球购物
澳大利亚在线生活方式商店:Mytopia
2018/07/08 全球购物
优秀毕业生求职推荐信范文
2013/11/21 职场文书
文明倡议书范文
2014/04/15 职场文书
专家推荐信模板
2014/05/09 职场文书
环境卫生标语
2014/06/09 职场文书
大学生交通专业求职信
2014/09/01 职场文书
新闻发布会活动策划方案
2014/09/15 职场文书
学习党的群众路线剖析材料
2014/10/09 职场文书
批评与自我批评发言稿
2014/10/15 职场文书
慰问信范文
2015/02/14 职场文书
导游词之开封禹王台风景区
2019/12/02 职场文书
Java使用HttpClient实现文件下载
2022/08/14 Java/Android