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复制内容到剪切板的实例代码(兼容IE与火狐)
Nov 19 Javascript
jQuery实现购物车多物品数量的加减+总价计算
Jun 06 Javascript
JavaScript中常用的六种互动方法示例
Mar 13 Javascript
Jquery给当前页或者跳转后页面的导航栏添加选中后样式的实例
Dec 08 Javascript
jQuery EasyUI Draggable拖动组件
Mar 01 Javascript
JS实现按钮控制计时开始和停止功能
Jul 27 Javascript
20个最常见的jQuery面试问题及答案
May 23 jQuery
vue里面v-bind和Props 利用props绑定动态数据的方法
Aug 27 Javascript
基于Angularjs-router动态改变Title值的问题
Aug 30 Javascript
在vue项目中优雅的使用SVG的方法实例详解
Dec 03 Javascript
JS实现图片轮播效果实例详解【可自动和手动】
Apr 04 Javascript
vue项目中仿element-ui弹框效果的实例代码
Apr 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命名空间(Namespace)的使用详解
2013/05/04 PHP
PHP处理excel cvs表格的方法实例介绍
2013/05/13 PHP
PHP使用in_array函数检查数组中是否存在某个值
2015/03/25 PHP
php查询whois信息的方法
2015/06/08 PHP
Laravel 微信小程序后端实现用户登录的示例代码
2019/11/26 PHP
一个用javascript写的select支持上下键、首字母筛选以及回车取值的功能
2009/09/09 Javascript
Mootools 1.2教程 输入过滤第一部分(数字)
2009/09/15 Javascript
js利用prototype调用Array的slice方法示例
2014/06/09 Javascript
jQuery基础知识小结
2014/12/22 Javascript
JavaScript中的原型链prototype介绍
2014/12/30 Javascript
JS 作用域与作用域链详解
2015/04/07 Javascript
AngularJs动态加载模块和依赖注入详解
2016/01/11 Javascript
JavaScript高级程序设计(第三版)学习笔记6、7章
2016/03/11 Javascript
js字符串引用的两种方式(必看)
2016/09/18 Javascript
Bootstrap Table从零开始
2017/06/30 Javascript
微信小程序实现文字从右向左无限滚动
2020/11/18 Javascript
js判断密码强度的方法
2020/03/18 Javascript
vue移动端下拉刷新和上滑加载
2020/10/27 Javascript
[03:37]2014DOTA2国际邀请赛 主赛事第一日胜者组TOPPLAY
2014/07/19 DOTA
[01:10:16]DOTA2上海特级锦标赛B组资格赛#2 Fnatic VS Spirit第一局
2016/02/27 DOTA
python查找第k小元素代码分享
2013/12/18 Python
探究Python多进程编程下线程之间变量的共享问题
2015/05/05 Python
Python图算法实例分析
2016/08/13 Python
Python加密方法小结【md5,base64,sha1】
2017/07/13 Python
Python实现PS滤镜特效之扇形变换效果示例
2018/01/26 Python
win8下python3.4安装和环境配置图文教程
2018/07/31 Python
如何关掉pycharm中的python console(图解)
2019/10/31 Python
python读取raw binary图片并提取统计信息的实例
2020/01/09 Python
Python pyautogui模块实现鼠标键盘自动化方法详解
2020/02/17 Python
HTML5 progress和meter控件_动力节点Java学院整理
2017/07/06 HTML / CSS
师范毕业生求职自荐信
2013/09/25 职场文书
餐饮总经理岗位职责
2014/03/07 职场文书
财务部副经理岗位职责范本
2014/06/17 职场文书
开会迟到检讨书范文
2015/05/06 职场文书
golang中的空接口使用详解
2021/03/30 Python
python3实现Dijkstra算法最短路径的实现
2021/05/12 Python