JS设置默认时间范围
来源:互联网 发布:世界时钟哪些软件好 编辑:程序博客网 时间:2024/05/22 14:44
说明:在web开发中,不可避免的会做查询页面和统计页面,两种页面都可能要设置默认统计时间范围,这可以通过JS来实现,代码如下:
var timeModule = ( function () {
/**
* 设置默认日期范围 (最近7天,如:2017-05-01 至 2017-05-07)
* */
initDateTime: function() {
var nowTime = new Date();
var d = nowTime.getDate();
var h = nowTime.getHours();
var m = nowTime.getMinutes();
var s = nowTime.getSeconds();
var initStartDate = new Date(nowTime.getTime() - 6*24*3600*1000 - (h*3600 + m*60 + s)*1000); //获取7天前的开始时间
var initEndDate = nowTime.Format(“yyyy-MM-dd”); //将当前时间格式化
…….. //设置开始日期、结束日期
},
/**
* 设置默认月份范围 (最近半年,如 2017-01 至 2017-06)
* */
initMonthTime: function() {
var nowTime = new Date();
var y= nowTime.getFullYear();
var initStartMonth = new Date(y, nowTime.getMonth()-4, 0).Format(“yyyy-MM”); //获取6个月前的开始月份
var initEndMonth = nowTime.Format(“yyyy-MM”); //将当前时间格式化
…….. //设置开始月份、结束月份
},
/**
* 设置默认年份范围 (最近5年,如 2013 至 2017)
* */
initYearTime: function() {
var nowTime = new Date();
var y= nowTime.getFullYear();
var initStartMonth = “” + y-4 + “”; //获取6个月前的开始月份
var initEndMonth = nowTime.Format(“yyyy”); //将当前时间格式化
…….. //设置开始月份、结束月份
}
})();
/**********************日期格式化工具*****************************/
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
“M+”: this.getMonth() + 1, //月份
“d+”: this.getDate(), //日
“h+”: this.getHours(), //小时
“m+”: this.getMinutes(), //分
“s+”: this.getSeconds(), //秒
“q+”: Math.floor((this.getMonth() + 3) / 3), //季度
“S”: this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.1.length));
for (var k in o)
if (new RegExp(“(” + k + “)”).test(fmt)) fmt = fmt.replace(RegExp.1.length == 1) ? (o[k]) : ((“00” + o[k]).substr((“” + o[k]).length)));
return fmt;
}
- JS设置默认时间范围
- datePicker设置时间范围
- js判断时间范围
- Easyui datebox设置默认时间 和 时间范围(七天,一个月)
- 【JAVAScript】js为日期框设置默认时间
- Android DatePicker 设置时间范围
- mysql默认时间设置
- Android设置默认时间
- 关于设置默认时间
- My97DatePicker设置默认时间
- Mycat范围分片设置默认分片
- 【设置时间】JS设置时间
- js根据当前时间的前一个月和后一个月设置默认时间
- 常用时间范围的查询的范围设置
- timestamp类型设置默认时间
- mysql列设置默认时间
- Android设置系统默认时间
- EasyUI--datebox设置默认时间
- Struts2 上传文件更改名字
- Ubuntu 14.04 LTS 安装 Mac 主题
- redis集群
- linux下”is not in the sudoers file“问题的解决办法
- Oracle中CONNECT BY...START WITH...的使用
- JS设置默认时间范围
- 堆和栈的区别(内存和数据结构)
- 模拟实现通讯录(文件存储)
- LeetCode 56 python
- hello world
- 深入理解javascript闭包
- 慕课网-Hello Spring Mvc
- Linux 格式化U盘为ext4格式
- Cocos2d-X游戏开发(六)