Theresia Vidi
Theresia Vidi

Reputation: 61

Convert milliseconds to minutes: Getting incorrect result

I have a total ammount of milliseconds (ie 4007587) and I want to display it as hours:minutes:seconds.

my PHP code:

$mil = 4007587
$timestamp = $mil/1000;
echo date("g:i:s", $timestamp);

the result should be 1:06:47 but my result is 8:06:47 what's wrong?

Upvotes: 1

Views: 1002

Answers (1)

Nick
Nick

Reputation: 147206

It's because date takes account of your local timezone. Try using gmdate instead:

$mil = 4007587;
$timestamp = $mil/1000;
// local timezone
echo date("g:i:s", $timestamp);
// UTC
echo gmdate("g:i:s", $timestamp);

Output

2:06:47
1:06:47

Upvotes: 4

Related Questions