现在巳知毫秒数为-60850977,怎么转换为还剩XX小时XX分钟?
我使用:
function timeFormat( timestamp, string ){
var time = "";
var dateTime = new Date(timestamp);
var year = dateTime.getFullYear();
var month = dateTime.getMonth()+1;
var date = dateTime.getDate();
var hours = dateTime.getHours();
var minutes = dateTime.getMinutes();
var seconds = dateTime.getSeconds();
month = month<10 ? "0"+month : month;
date = date<10 ? "0"+date : date;
seconds = seconds<10 ? "0"+seconds : seconds;
hours = hours<10 ? "0"+hours : hours;
minutes = minutes<10 ? "0"+minutes : minutes;
seconds = seconds<10 ? "0"+seconds : seconds;
switch (string) {
case "yyyy-mm-dd":
time = year + "-" + month + "-" + date;
break;
case "yyyy-mm-dd hh:mm":
time = year + "-" + month + "-" + date + " " + hours + ":" + minutes;
break;
case "yyyy-mm-dd hh:mm:ss":
time = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
break;
case "yyyy/mm/dd":
time = year + "/" + month + "/" + date;
break;
case "hh:mm:ss":
time = hours + ":" + minutes + ":" + seconds;
break;
default:
time = year + "-" + month + "-" + date;
}
return time;
}
timeFormat(-60850977,"hh:mm:ss"),使用这个方法后还是无法转换。请问是怎么回事?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
测试了一下,代码没毛病。。。。
不过可以简化一下,写的太啰嗦了;
首先 -60850977 这时间是1969年,是要跟当前的时间比吗? 还剩多少时间不应该是比当前时间大吗?
测试了下---结果:

你的代码在chrome控制台运行没问题,得到了"15:05:49"这个。
你的代码是对时间进行了格式化,而你的需求是倒计时,两回事吗!!!
找到一篇博文,方法还不错,你试试:http://xp9802.iteye.com/blog/...,我这里测试为16小时54分钟10秒
负数怎么转,把负号去掉。