页面显示当前时间

$.ajax({
  type: "POST",
  url: ctx.path+'/api/hPage/getLocalTime.json',
  traditional: true,
  dataType: "json",
  success: function(data){
  if(data.rs==1){
  var local_time=data.data;
  var a=new Date(local_time);
  timer(a);
 }else{
  layer.msg('获取服务器时间失败!', {icon: 0});
 }
}
});
function timer(local_time){
setTimeout(function(){
T=T-1+2;
var date=new Date(local_time.getTime()+T*1000);
var year=date.getFullYear();
var month=date.getMonth()+1;
var day=date.getDate();
var hour=date.getHours();
var minute=date.getMinutes();
var second=date.getSeconds();
if(second<=9) second="0"+second;
if(minute<=9) minute="0"+minute;
if(hour<=9) hour="0"+hour;
var c=year+'年'+month+'月'+day+'日'+hour+':'+minute+':'+second;
$("#times").html(c);
timer(local_time);
},1000);
}

posted @ 2016-06-06 15:35  馳騁衿琾  阅读(269)  评论(0编辑  收藏  举报