JS时间相减得出天数

乱编乱写 5493 Views 0 Comments

JS时间相减得出天数

var date = new Date();
var y = date.getFullYear();
var m = date.getMonth();
var d = date.getDate();
 
var endDate = '2013-01-04';
var array = endDate.split("-");
var endTime = new Date(parseInt(array[0]), parseInt(array[1]) - 1, parseInt(array[2]));
var nowTime = new Date(parseInt(y), parseInt(m), parseInt(d));
var day = (Number(nowTime) - Number(endTime)) / (1000 * 60 * 60 * 24);
 
alert(endDate + ' 距今已过 ' + day + ' 天');

标签: JS,

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
loading