码迷,mamicode.com
首页 > Web开发 > 详细

js获取最近几天的日期(转载)

时间:2014-09-03 19:37:17      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   java   ar   2014   cti   log   html   

bubuko.com,布布扣

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>js获取日期:前天、昨天、今天、明天、后天 </title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
Date.prototype.DateAdd = function(strInterval, Number)
{
var dtTmp = this;
switch (strInterval) {
case ‘s‘ :return new Date(Date.parse(dtTmp) + (1000 * Number));
case ‘n‘ :return new Date(Date.parse(dtTmp) + (60000 * Number));
case ‘h‘ :return new Date(Date.parse(dtTmp) + (3600000 * Number));
case ‘d‘ :return new Date(Date.parse(dtTmp) + (86400000 * Number));
case ‘w‘ :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
case ‘q‘ :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case ‘m‘ :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case ‘y‘ :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
}
}
function GetDateStr2(AddDayCount)
{
var dd = new Date();
ddd = dd.DateAdd(‘d‘,AddDayCount);//三天后
var m = ddd.getMonth()+1;//获取当前月
var d = ddd.getDate();
return m+"-"+d;
}
document.write("前天:"+GetDateStr2(-2));
document.write("<br />昨天:"+GetDateStr2(-1));
document.write("<br />今天:"+GetDateStr2(0));
document.write("<br />明天:"+GetDateStr2(1));
document.write("<br />后天:"+GetDateStr2(2));
document.write("<br />大后天:"+GetDateStr2(3));
</script>
</body>
</html>

js获取最近几天的日期(转载)

标签:blog   http   io   java   ar   2014   cti   log   html   

原文地址:http://www.cnblogs.com/cainiaoz/p/3954318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!