码迷,mamicode.com
首页 > Web开发 > 详细

js日期操作时间看板

时间:2015-06-14 18:26:34      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

var nowTime = null;
//获取服务器时间
function GetTime() {
$.ajax({
url:config._domain + "/AjaxAuctionCenter/GetDbTime",
data: {},
type: "POST",
async:false,
success: function (data) {
if (data != null) {
nowTime = data;
}
}
});
}
$(function() {

/*设置日期时间*/
GetTime();
setInterval(setDate, 30000);
var myDate = new Date(Date.parse(nowTime.replace(/-/g, "/")));
setDate();
function setDate() {
var myYear, myMonth, myDay, myHours, myMinutes;
myYear = myDate.getFullYear();
myMonth = myDate.getMonth() + 1;
myDay = myDate.getDay();
myHours = myDate.getHours();
myMinutes = myDate.getMinutes();
//console.log(myDay)
//myDate = myDate.getDate();
$(‘#my_year‘).html(myYear);
$(‘#my_month‘).html(toDuble(myMonth));
$(‘#my_day‘).html(toDuble(myDate.getDate()));
$(‘#my_hours‘).html(toDuble(myHours));
$(‘#my_minutes‘).html(toDuble(myMinutes));
$(‘#my_week‘).html(myDay);


try {
switch (myDay) {
case 1:
$(‘#my_week‘).html("一");
break;
case 2:
$(‘#my_week‘).html("二");
break;
case 3:
$(‘#my_week‘).html("三");
break;
case 4:
$(‘#my_week‘).html("四");
break;
case 5:
$(‘#my_week‘).html("五");
break;
case 6:
$(‘#my_week‘).html("六");
break;
case 0:
$(‘#my_week‘).html("日");
break;
default:
}


} catch (e) {

}

myDate.setTime(myDate.getTime() + 30000);
}

function toDuble(num) {
if (num < 10) {
return ‘0‘ + num;
} else {
return ‘‘ + num;
}
}

});

 

js日期操作时间看板

标签:

原文地址:http://www.cnblogs.com/phone15138028025/p/4575251.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!