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

convert milliseconds to a time

P: n/a
hello

I've tried to convert some milliseconds to a time format.

$ms = 100000 // 1min 40sec
echo strftime('%H:%M:%S', $ms/1000);

i expect the result is: "00:01:40"

but the result ist: "01:01:40"

i think this is a problem of a locale.
is there another easy way to covert a given ammout of milliseconds to a
time format?

thanks
//B

May 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Benny Schudel" <be**********@gmail.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
hello

I've tried to convert some milliseconds to a time format.

$ms = 100000 // 1min 40sec
echo strftime('%H:%M:%S', $ms/1000);

i expect the result is: "00:01:40"

but the result ist: "01:01:40"

i think this is a problem of a locale.
is there another easy way to covert a given ammout of milliseconds to a
time format?

strftime takes a pattern and a timestamp as parameter. The timestamp is
milliseconds since the EPOCH time, January 1, 1970 at midnight at GMT. Now
my guess is that the one hour leap comes from the fact that you live in a +1
timezone and the +1 hour is being accounted for when you use strftime. I
tried the same script and just as expected I got 02:01:40 since Helsinki is
in GMT+2 timezone.

I didn't test, but I'd guess the sisterfunction of strftime, gmstrftime
would do the trick since it assumes GMT time is being used and doesn't add
any timezone hours to the time. Therefore it might provide a solution.

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
May 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.