js 获取时间对象代码
/**
* 获取时间对象
*/
function getDateObj(addDayCount) {
var dd = new Date();
dd.setDate(dd.getDate()+addDayCount);//获取addDayCount天后的日期
var y = dd.getFullYear();
var m = dd.getMonth()+1;//获取当前月份的日期
var d = dd.getDate();
var h = dd.getHours();
var M = dd.getMinutes();
var s = dd.getSeconds();
var w = "";
var numOfWeek = dd.getDay();
switch (numOfWeek) {
case 0: w = "星期日"; break;
case 1: w = "星期一"; break;
case 2: w = "星期二"; break;
case 3: w = "星期三"; break;
case 4: w = "星期四"; break;
case 5: w = "星期五"; break;
case 6: w = "星期六"; break;
}
var timeObject = {
‘year‘ : y,
‘month‘ : m,
‘day‘ : d,
‘hour‘ : h,
‘minute‘: M,
‘second‘: s,
‘week‘ : w
}
return timeObject;
}
window.ready = function(){
var t = getDateObj(1);
alert(t.year + ‘-‘ +
t.month + ‘-‘ +
t.day + ‘ ‘ +
t.hour + ‘:‘ +
t.minute + ‘:‘ +
t.second + ‘ ‘ +
t.week);
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。