标签:style blog color io ar sp div on cti
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传负数即可
标签:style blog color io ar sp div on cti
原文地址:http://www.cnblogs.com/shinima/p/4016433.html