获取本月的第一天和最后一天
2015-11-20 17:01
330 查看
var firstDate = new Date(); firstDate.setDate(1); //第一天 var endDate = new Date(firstDate); endDate.setMonth(firstDate.getMonth()+1); endDate.setDate(0); alert("第一天:"+firstDate.format('yyyy-MM-dd 00:00:00')+" 最后一天:"+endDate.format('yyyy-MM-dd 23:59:59'));
//时间格式化 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, //month "d+": this.getDate(), //day "h+": this.getHours(), //hour "m+": this.getMinutes(), //minute "s+": this.getSeconds(), //second "q+": Math.floor((this.getMonth() + 3) / 3), //quarter "S": this.getMilliseconds() //millisecond } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); } for (var k in o) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; }
相关文章推荐
- (一)【转】asp.net mvc生成验证码
- C# toString()转换详细(转)
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- centos7 常用命令--查看当前用户的4种方法
- iOS项目开发实战(Swift)—Button和Alert学习
- Aspose.Excel.dll Excel导入、导出
- 三篇文章,讲清浏览器渲染机制
- 文件上传及进度显示
- PHP连接mysql
- Centos6.6 本地 yum 配置
- Service not registered
- LightOJ 1051 - Good or Bad (dp)
- 小P的故事——神奇的换零钱
- linux设备驱动归纳总结(一):内核的相关基础概念
- ListView使用完全讲解
- DFS入门:全排列算法及POJ 1564 Sum it up详解
- uva112
- 写文件,并且规定文件的权限
- android studio 教程
- 从学员角度体验教练技术之考驾照