时间戳转时间

var addtime =$scope.days;
var date = new Date($('.curTime').html().replace(/-/g, '/'));
var new1 = Number(date.getTime()/1000) + Number(addtime)*86400;
var newTime = timestampToTime(new1);//timestampToTime调用
$('.data_result').html(newTime)
// 时间戳转时间
function timestampToTime(timestamp) {
var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1)+ '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes();
// s = date.getSeconds();
return Y+M+D+h+m;
}

猜你喜欢

转载自www.cnblogs.com/loveAline/p/9289254.html