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 去除数组的重复元素
May 04 Javascript
关于document.cookie的使用javascript
Oct 29 Javascript
JavaScript NodeTree导航栏(菜单项JSON类型/自制)
Feb 01 Javascript
js实现在页面上弹出蒙板技巧简单实用
Apr 16 Javascript
JavaScript实现继承的4种方法总结
Oct 16 Javascript
jquery计算鼠标和指定元素之间距离的方法
Jun 26 Javascript
jQuery post数据至ashx实例详解
Nov 18 Javascript
JavaScript组件开发之输入框加候选框
Mar 10 Javascript
微信小程序图表插件wx-charts用法实例详解
May 20 Javascript
vue 中使用 watch 出现了如下的报错的原因分析
May 21 Javascript
微信小程序实现3D轮播图效果(非swiper组件)
Sep 21 Javascript
easyUI 实现的后台分页与前台显示功能示例
Jun 01 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中的Traits
2015/07/29 PHP
使用ThinkPHP的自动完成实现无限级分类实例详解
2016/09/02 PHP
Yii框架响应组件用法实例分析
2019/09/04 PHP
ThinkPHP5&5.1实现验证码的生成、使用及点击刷新功能示例
2020/02/07 PHP
基于jQuery的实现简单的分页控件
2010/10/10 Javascript
javascript学习笔记(七) js函数介绍
2012/06/19 Javascript
Array 重排序方法和操作方法的简单实例
2014/01/24 Javascript
详谈jQuery操纵DOM元素属性 attr()和removeAtrr()方法
2015/01/22 Javascript
js正则匹配出所有图片及图片地址src的方法
2015/06/08 Javascript
AngularJS中如何使用$parse或$eval在运行时对Scope变量赋值
2016/01/25 Javascript
浅谈jQuery中的$.extend方法来扩展JSON对象
2017/02/12 Javascript
react-native之ART绘图方法详解
2017/08/08 Javascript
Vue + better-scroll 实现移动端字母索引导航功能
2018/05/07 Javascript
JavaScript中变量提升与函数提升经典实例分析
2018/07/26 Javascript
jQuery实现侧边栏隐藏与显示的方法详解
2018/12/22 jQuery
JS 5种遍历对象的方式
2020/06/16 Javascript
vue style width a href动态拼接问题的解决
2020/08/07 Javascript
Python AES加密实例解析
2018/01/18 Python
python实现简易版计算器
2020/06/22 Python
python实现抖音视频批量下载
2018/06/20 Python
Python利用heapq实现一个优先级队列的方法
2019/02/03 Python
python计算二维矩形IOU实例
2020/01/18 Python
python爬虫模块URL管理器模块用法解析
2020/02/03 Python
Python猜数字算法题详解
2020/03/01 Python
python raise的基本使用
2020/09/10 Python
Anaconda使用IDLE的实现示例
2020/09/23 Python
Python图像读写方法对比
2020/11/16 Python
Selenium+BeautifulSoup+json获取Script标签内的json数据
2020/12/07 Python
用CSS3实现背景渐变的方法
2015/07/14 HTML / CSS
德国团购网站:Groupon德国
2018/03/13 全球购物
Linux面试经常问的文件系统操作命令
2016/10/04 面试题
计算机相关的自我评价
2014/01/15 职场文书
法律进社区活动总结
2015/05/07 职场文书
2016小学教师读书心得体会
2016/01/13 职场文书
Python OpenCV 图像平移的实现示例
2021/06/04 Python
python实现层次聚类的方法
2021/11/01 Python