我正在尝试将 unix 时间戳转换为可读时间。我已经尝试了所有能找到的解决方案,但没有一个仍然有效。我不想使用任何模块或框架。我很感激一些转换帮助。( Angular )请不要链接到其他问题。我全部读过。谢谢你
var unix = Math.round(+new Date()/1000);
console.log(unix) //works
function secondstotime(unix)
{
var t = new Date(1970,0,1);
t.setSeconds(unix);
var s = t.toTimeString().substr(0,8);
if(unix > 86399)
s = Math.floor((t - Date.parse("1/1/70")) / 3600000) + s.substr(2);
console.log(s);
}
secondstotime();
最佳答案
在 angularjs 中,您可以简单地使用日期过滤器来转换 Unix 时间戳(秒)。只需将 Unix 时间戳乘以 1000 即可使其成为毫秒时间戳。这是代码
<p>{{1469424998 * 1000 | date:'hh:mm:ss'}}</p>
或者您可以使用一些外部库(例如momentjs)将Unix时间戳(秒)转换为日期时间,如下所示
var day = moment.unix(1469424998);
console.log(day.format("hh:mm:ss"));
希望对你有帮助
关于javascript - 将 UNIX 转换为 HH-MM-SS Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38560272/