By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Converting milliseconds to Days, Hours, Minutes, Seconds

P: n/a
I need a routine to convert milliseconds to
a traditional dd:hh:mm:ss or four separate
variables that I can display.

I am not wanting to display a date but rather
the interval between two times.

Thanks,

Deepa :-)
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Deepa wrote on 05 dec 2003 in comp.lang.javascript:
I need a routine to convert milliseconds to
a traditional dd:hh:mm:ss or four separate
variables that I can display.


<script>

function two(x) {return ((x>9)?"":"0")+x}
function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}

function time(ms) {
var sec = Math.floor(ms/1000)
ms = ms % 1000
t = three(ms)

var min = Math.floor(sec/60)
sec = sec % 60
t = two(sec) + ":" + t

var hr = Math.floor(min/60)
min = min % 60
t = two(min) + ":" + t

var day = Math.floor(hr/60)
hr = hr % 60
t = two(hr) + ":" + t
t = day + ":" + t

return t
}

document.write(time(12034056070))
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2

P: n/a
Thanks!
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.29...
Deepa wrote on 05 dec 2003 in comp.lang.javascript:
I need a routine to convert milliseconds to
a traditional dd:hh:mm:ss or four separate
variables that I can display.


<script>

function two(x) {return ((x>9)?"":"0")+x}
function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}

function time(ms) {
var sec = Math.floor(ms/1000)
ms = ms % 1000
t = three(ms)

var min = Math.floor(sec/60)
sec = sec % 60
t = two(sec) + ":" + t

var hr = Math.floor(min/60)
min = min % 60
t = two(min) + ":" + t

var day = Math.floor(hr/60)
hr = hr % 60
t = two(hr) + ":" + t
t = day + ":" + t

return t
}

document.write(time(12034056070))
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.