how can i convert seconds to HH-MM-SS with javascript ?
+6
A:
Don't you know datejs? it is a must know.
Using datejs, just write something like:
(new Date).clearTime()
.addSeconds(15457)
.toString('H:mm:ss');
Cleiton
2009-08-24 14:33:46
thx but can you show me how it will help me ??
Yassir
2009-08-24 14:43:11
sure, I edited my answer.
Cleiton
2009-08-24 15:01:25
thx for the help :)
Yassir
2009-08-24 16:15:05
exactly what I'm looking for. Thanks!
huy
2010-06-09 08:02:11
+1
A:
I don't think any built-in feature of the standard Date object will do this for you in a way that's more convenient than just doing the math yourself.
hours = totalSeconds / 3600;
totalSeconds %= 3600;
minutes = totalSeconds / 60;
seconds = totalSeconds % 60;
T.J. Crowder
2009-08-24 14:39:37
Oh, this just gives you the numbers. I left the formatting as an exercise for the reader. :)
T.J. Crowder
2009-08-24 16:21:52
A:
I've used this code before to create a simple timespan object:
function TimeSpan(time) {
this.hours = 0;
this.minutes = 0;
this.seconds = 0;
while(time >= 3600)
{
this.hours++;
time -= 3600;
}
while(time >= 60)
{
this.minutes++;
time -= 60;
}
this.seconds = time;
}
var timespan = new Timespan(3662);
smack0007
2009-08-24 14:41:13
+2
A:
hours = parseInt( totalSec / 3600 ) % 24;
minutes = parseInt( totalSec / 60 ) % 60;
seconds = totalSec % 60;
result = (hours < 10 ? "0" + hours : hours) + "-" + (minutes < 10 ? "0" + minutes : minutes) + "-" + (seconds < 10 ? "0" + seconds : seconds);
knizz
2009-08-24 14:44:49