convert milliseconds to a time

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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?


Re: convert milliseconds to a time

Quoted text here. Click to load it

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 | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)  

Site Timeline