首页 技术 正文
技术 2022年11月8日
0 收藏 820 点赞 1,374 浏览 2036 个字
当初做统计业务需要处理时间 周报:本周 上周 下周 近一周    月报上月 本月  等 需要使用时间处理 所以扩展了这些方法 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body></body>
</html>
<script type="text/javascript">
var _DateTostring = Date.prototype.toString;
Date.prototype.add = function (type, value) {
if (!type || value==undefined||value==null || isNaN(value)) {
throw "增加的类型不存在或者值不是一个数字"
}
switch (type) {
case "d":
case "D":
this.setDate(this.getDate() + value);
break
case "M":
case "m":
this.setMonth(this.getMonth() + value);
break;
case "Y":
case "y":
this.setFullYear(this.getFullYear() + value);
break;
case "day":
case "DAY":
//本周的第几天
var day =this.getDay()==0?7:this.getDay(); var i = Math.abs(value);
if (value == 0) { this.addDate(-(day-1));//本周
return;
}
value < 0 ? this.addDate(-(day + 7 * i - 1)) : i > 1 ? this.addDate(7 - day + ((i - 1) * 7)+1) : this.addDate(7 - day+1); break;
}
var date = this;
return date;
}
Date.prototype.addDate = function (value) {
this.add("d", value);
}
Date.prototype.addMonth = function (value) {
this.add("m", value);
}
Date.prototype.addDay = function (value) {
this.add("day", value);
}
Date.prototype.addYear = function (value) {
this.add("y", value);
}
Date.prototype.toString = function (fmt) {
if (fmt == undefined) {
return _DateTostring.call(this);
}
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, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
var date = new Date();
//date.addDate(1);//当前时间基础加上12天
//date.addDate(-1);//当前时间基础减去12天
//date.addMonth(-1);//当前时间基础减去1月
//date.addMonth(1);//当前时间基础加上一月
//date.addYear(1);//当前时间基础加上一年
//date.addYear(-1);//当前时间基础减去一年
//date.addDay(-1);//上周
//date.addDay(-2);//前2周
//date.addDay(0);//本周
//console.log(date.toString("yyyy-MM-dd"));//格式化日期
// console.log(date.toString());
// date.addDay(-1);//下周</script>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896