首页 > Web开发 > 详细

js处理日期的一些整理(js获取给定日期前一天的日期)

时间:2014-10-14 16:42:10      阅读:220      评论:0      收藏:0      [点我收藏+]
 var date = new Date();
 alert(date);//获取当前时间
 alert(date.getFullYear());//获取当前年分
 alert(date.getMonth());//获取月份(获取当前月份要加1)
 alert(date.getDate());//获取当前日期的几号
 alert(date.getDay());//获取当前是星期几
 alert(date.getTime());//获取距离1970/01/01 至今的毫秒
settime()是向 1970/01/01 08:00:00 添加毫秒,并显示新的日期和时间。
var
date = new Date();
date.setTime(
24*1000*60*60); document.write(date);//输出Thu Jan 02 1970 08:00:00 GMT+0800 (China Standard Time)
//获取指定日期后几天(明天)的日期   d是那一天,i是后几天
function getTomorrow(d, i) {
var date = new Date(d); var tomorrow_milliseconds = date.getTime() + 1000 * 60 * 60 * 24 * i; var tomorrow= new Date(); tomorrow.setTime(tomorrow_milliseconds); var strYear = tomorrow.getFullYear(); var strDay = tomorrow.getDate(); var strMonth = tomorrow.getMonth() + 1; if (strMonth < 10) { strMonth = "0" + strMonth; } datastr = strYear + "/" + strMonth + "/" + strDay; return datastr; }
//获取给定日期前几天的日期i传负数即可

 

js处理日期的一些整理(js获取给定日期前一天的日期)

原文:http://www.cnblogs.com/shinima/p/4016433.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!