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 相关文章推荐
Javascript实例教程(19) 使用HoTMetal(1)
Dec 23 Javascript
jQuery dialog 异步调用ashx,webservice数据的代码
Aug 03 Javascript
Firefox/Chrome/Safari的中可直接使用$/$$函数进行调试
Feb 13 Javascript
js 为label标签和div标签赋值的方法
Aug 08 Javascript
JavaScript设计模式经典之命令模式
Feb 24 Javascript
详解JS异步加载的三种方式
Mar 07 Javascript
基于Vue实现支持按周切换的日历
Sep 24 Javascript
微信小程序之选项卡的实现方法
Sep 29 Javascript
使用3D引擎threeJS实现星空粒子移动效果
Sep 13 Javascript
AngularJs用户输入动态模板XSS攻击示例详解
Apr 21 Javascript
详解基于Vue,Nginx的前后端不分离部署教程
Dec 04 Javascript
基于javascript的无缝滚动动画实现2
Aug 07 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
制作美丽的拉花
2021/03/03 冲泡冲煮
php标签云的实现代码
2012/10/10 PHP
基于Linux调试工具strace与gdb的常用命令总结
2013/06/03 PHP
PHP进程通信基础之信号量与共享内存通信
2017/02/19 PHP
PHP 图片合成、仿微信群头像的方法示例
2019/10/25 PHP
use jscript List Installed Software
2007/06/11 Javascript
jquery插件validate验证的小例子
2013/05/08 Javascript
Js,alert出现乱码问题的解决方法
2013/06/19 Javascript
HTML5实现留言和回复页面样式
2015/07/22 Javascript
通过设置CSS中的position属性来固定层的位置
2015/12/14 Javascript
jQuery图片切换动画特效
2016/11/02 Javascript
Vuejs 2.0 子组件访问/调用父组件的方法(示例代码)
2018/02/08 Javascript
Express的HTTP重定向到HTTPS的方法
2018/06/06 Javascript
解决vue router组件状态刷新消失的问题
2018/08/01 Javascript
关于js陀螺仪的理解分析
2019/04/11 Javascript
node.js Promise对象的使用方法实例分析
2019/12/26 Javascript
Vue组件为什么data必须是一个函数
2020/06/11 Javascript
python利用rsa库做公钥解密的方法教程
2017/12/10 Python
python实现文件的分割与合并
2019/08/29 Python
python GUI库图形界面开发之PyQt5日期时间控件QDateTimeEdit详细使用方法与实例
2020/02/27 Python
4行Python代码生成图像验证码(2种)
2020/04/07 Python
Jupyter Notebook的连接密码 token查询方式
2020/04/21 Python
用python获取txt文件中关键字的数量
2020/12/24 Python
利用CSS3的flexbox实现水平垂直居中与三列等高布局
2016/09/12 HTML / CSS
德国最大的服装、鞋子和配件在线商店之一:Outfits24
2019/07/23 全球购物
美国椅子和沙发制造商:La-Z-Boy
2020/10/25 全球购物
什么是Smart Navigation?
2016/07/03 面试题
客服工作职责
2013/12/11 职场文书
商业活动邀请函
2014/02/04 职场文书
取保候审保证书
2014/04/30 职场文书
小学校长先进事迹材料
2014/05/13 职场文书
2014年学校卫生工作总结
2014/11/20 职场文书
后勤工作个人总结
2015/02/28 职场文书
史上最牛辞职信
2015/05/13 职场文书
让子弹飞观后感
2015/06/11 职场文书
初二数学教学反思
2016/02/17 职场文书