標籤: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傳負數即可
js處理日期的一些整理(js擷取給定日期前一天的日期)