首页 > Web开发 > 详细

js 获取时间对象代码

时间:2014-07-16 17:57:40      阅读:271      评论:0      收藏:0      [点我收藏+]

/**
* 获取时间对象
*/
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);

}

js 获取时间对象代码,布布扣,bubuko.com

js 获取时间对象代码

原文:http://www.cnblogs.com/tancp/p/3847564.html

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