我正在尝试找到一种将秒转换为时间格式的好方法.
I am trying to find a good solution for converting seconds to time format.
我有此功能,到目前为止可以满足我的需求.
I have this function which works fine for my needs so far.
function secondstotime(secs) { var t = new Date(1970,0,1); t.setSeconds(secs); var s = t.toTimeString().substr(0,8); if(secs > 86399) s = Math.floor((t - Date.parse("1/1/70")) / 3600000) + s.substr(2); return s; } alert(secondstotime(1920));因此您可以在jsfiddle中运行它 jsfiddle/7Pp5z/
So you can run this in jsfiddle jsfiddle/7Pp5z/
所以这很好用,可以工作数小时等等,但是我希望在时间的左边去除零.举个例子
So this works great and works for hours etc but i am looking to strip the zeros to the left of the time. Taking the example
我要00:32:00
i want 00:32:00
变成32:00,这样在输出到浏览器时看起来会更好
to become 32:00 so it looks better that way when outputted to the browser
有人可以告诉我执行此操作的最佳方法吗,或者有人可以共享其他功能吗?
Can someone tell me the best way to do this or does anyone have another function they could possibly share.
谢谢
推荐答案输入以下条件:
if(s.substr(0, 2) == 00) return s.substr(3);工作演示 jsfiddle/7Pp5z/2/
更多推荐
将秒转换为时间格式
发布评论