/**
* 判断年份是否为润年
*
* @param {Number} year
*/
function isLeapYear(year) {
return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
/**
* 获取某一年份的某一月份的天数
*
* @param {Number} year
* @param {Number} month
*/
function getMonthDays(year, month) {
return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] || (isLeapYear(year) ? 29 : 28);
} /**
* 获取某年的某天是第几周
* @param {Number} y
* @param {Number} m
* @param {Number} d
* @returns {Number}
*/
function getWeekNumber(now) {
year = now.getFullYear(),
month = now.getMonth(),
days = now.getDate();
//那一天是那一年中的第多少天
for (var i = 0; i < month; i++) {
days += getMonthDays(year, i);
} //那一年第一天是星期几
var yearFirstDay = new Date(year, 0, 1).getDay() || 7; var week = null;
if (yearFirstDay == 1) {
week = Math.ceil(days / yearFirstDay);
} else {
days -= (7 - yearFirstDay + 1);
week = Math.ceil(days / 7) + 1;
} return week;
} //一个月有多少天
function getCountDays(curDate) { /* 获取当前月份 */
var curMonth = curDate.getMonth();
/* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
curDate.setMonth(curMonth + 1);
/* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
curDate.setDate(0);
/* 返回当月的天数 */
return curDate.getDate();
} function getWeekStart(curDate) { var curMonth = curDate.getMonth();
curDate.setDate(curDate.getDate() + 1 - curDate.getDay());//
return curDate;
}
function getWeekEnd(curDate) { curDate.setDate(curDate.getDate() + 7 - curDate.getDay());
return curDate;
}

最新文章

  1. 图解GitHub基本操作
  2. 快速入门系列--CLR--01基本概念
  3. QA:Failed to deploy artifacts from/to snapshots XX Failed to transfer file Return code is: 405, ReasonPhrase:Method Not Allowed.
  4. 深入理解OpenGL拾取模式(OpenGL Picking)
  5. mount/umount系统调用
  6. Struts2运行流程分析
  7. Android使用Google推荐的联网框架Volley,让连接网络更加简单
  8. IBATIS处理typeHandler类容易范的SQLException总结
  9. extjs+amcharts生成3D柱状图和数据表格使用总结
  10. (从零开始java开发) IDEA+MAVEN构建一个webapp骨架项目(解决一直downloading问题)
  11. OvS: data structure analysis
  12. python 中__setattr__, __getattr__,__getattribute__, __call__使用方法
  13. React点击操作自动定位到另外一个元素
  14. 八大排序算法——基数排序(动图演示 思路分析 实例代码java 复杂度分析)
  15. 经纬度编码方法推荐-plus code简介
  16. Vxlan学习笔记——原理(转)
  17. C# 定时器和队列结合,卖包子啦,Timer、 AutoResetEvent、 ManualResetEvent
  18. DDD领域模型数据访问权限之用户权限(十)
  19. 设置Eclipse的类文件和xml文件代码自动补全
  20. Oracle EBS 银行账户API

热门文章

  1. 数据库系统原理及其应用总结---ShinePans
  2. 使用断言assert
  3. RPM包查询
  4. 使用 Intel HAXM 为 Android 模拟器加速,媲美真机(转)
  5. 查看Linux相关信息
  6. asp.net 发送邮件代码 System.Net.Mail
  7. sublime text3 安装package control
  8. flask开发restful api系列(3)--利用alembic进行数据库更改
  9. 关于lambda表达式树
  10. ROW_NUMBER()/RANK()/DENSE_RANK()/ntile() over()