现在的位置: 首页 > 综合 > 正文

javascript日期与时间

2014年02月26日 ⁄ 综合 ⁄ 共 726字 ⁄ 字号 评论关闭

 

function getCurDate()
{
   today= new Date();
   year= today.getYear() + 1900;  
   month= today.getMonth() + 1;
   if (month<10){
month='0'+month;
   }
   day= today.getDate();
   if (day<10){
day='0'+day;
   }
   hours= today.getHours();
   if(hours<10){
hours='0'+hours;
   }
   minutes = today.getMinutes();
   if(minutes<10) minutes = '0'+minutes;
   seconds = today.getSeconds();
   if(seconds<10) seconds='0'+seconds
  
now = year + '-' + month + '-' + day + ' ' + hours + ":" + minutes + ":" + seconds;  
   return now;
}
new Date().getTime()的值精确到毫秒值
Date date1 = new Date();
Date date2 = new Date();
var daydiff = (date1.getTime()-date2.getTime())/(24*60*60*1000);
Date date1 = new Date();
Date date2 = new Date();
var hourdiff = (date1.getTime()-date2.getTime())/(60*60*1000);
 

 

抱歉!评论已关闭.