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下获得客户端操作系统的函数代码(1:vista,2:windows7,3:2000,4:xp,5:2003,6:2008)
Oct 31 Javascript
js字符编码函数区别分析
Dec 28 Javascript
JS中的substring和substr函数的区别说明
May 07 Javascript
实例讲解jQuery EasyUI tree中state属性慎用
Apr 01 Javascript
JS+CSS3实现超炫的散列画廊特效
Jul 16 Javascript
深入理解javascript作用域第二篇之词法作用域和动态作用域
Jul 24 Javascript
Node.js连接postgreSQL并进行数据操作
Dec 18 Javascript
Dropify.js图片宽高自适应的方法
Nov 27 Javascript
让webpack+vue-cil项目不再自动打开浏览器的方法
Sep 27 Javascript
原生js实现each方法实例代码详解
May 27 Javascript
通过js给网页加上水印背景实例
Jun 17 Javascript
vue Tab切换以及缓存页面处理的几种方式
Nov 05 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中在数据库中保存Checkbox数据(1)
2006/10/09 PHP
几个实用的PHP内置函数使用指南
2014/11/27 PHP
php有效防止同一用户多次登录
2015/11/19 PHP
如何写php守护进程(Daemon)
2015/12/30 PHP
Javascript 判断 object 的特定类转载
2007/02/01 Javascript
禁止JQuery中的load方法装载IE缓存中文件的方法
2009/09/11 Javascript
js和jquery设置disabled属性为true使按钮失效
2014/08/07 Javascript
jquery实现图片随机排列的方法
2015/05/04 Javascript
jquery.gridrotator实现响应式图片展示画廊效果
2015/06/23 Javascript
jquery合并表格中相同文本的相邻单元格
2015/07/17 Javascript
Javascript类型系统之undefined和null浅析
2016/07/13 Javascript
JavaScript新增样式规则(推荐)
2016/07/19 Javascript
javascript将中国数字格式转换成欧式数字格式的简单实例
2016/08/02 Javascript
ASP.NET jquery ajax传递参数的实例
2016/11/02 Javascript
jQuery Easyui datagrid连续发送两次请求问题
2016/12/13 Javascript
Bootstrap笔记之缩略图、警告框实例详解
2017/03/09 Javascript
Bootstrap输入框组件使用详解
2017/06/09 Javascript
[js高手之路]从原型链开始图解继承到组合继承的产生详解
2017/08/28 Javascript
详解原生JS回到顶部
2019/03/25 Javascript
react MPA 多页配置详解
2019/10/18 Javascript
vue+elementUI组件table实现前端分页功能
2020/11/15 Javascript
基于JavaScript实现表格隔行换色
2020/05/08 Javascript
Python使用PDFMiner解析PDF代码实例
2017/03/27 Python
python和mysql交互操作实例详解【基于pymysql库】
2019/06/04 Python
Python基础学习之基本数据结构详解【数字、字符串、列表、元组、集合、字典】
2019/06/18 Python
Python应用实现处理excel数据过程解析
2020/06/19 Python
用Python开发app后端有优势吗
2020/06/29 Python
外贸业务员求职信范文
2013/12/12 职场文书
仓库理货员岗位职责
2013/12/18 职场文书
2014年党员个人工作总结
2014/12/02 职场文书
老公婚前保证书
2015/02/28 职场文书
2015年女职工工作总结
2015/05/15 职场文书
初中生物教学随笔
2015/08/15 职场文书
导游词之杭州西湖
2019/09/19 职场文书
使用feign服务调用添加Header参数
2021/06/23 Java/Android
一文了解MySQL二级索引的查询过程
2022/02/24 MySQL