The problem with PHP today

Take a look at the code below:

$t=77; date("H:i:s", $t); 

He returns

 21:01:17 

The correct result, of course, should be something like 00:01:17.

The value of $ t is indeed the value in seconds returned by the GData API, trought($videoEntry->getVideoDuration()) .

How can I fix this problem?

+4
source share
4 answers

date is timezone specific. You need to set it to GMT to get the desired results.

 date_default_timezone_set('GMT'); $t=77; echo date("H:i:s", $t); 
+8
source

The second argument to date () is the unix timestamp - in other words, this is the number of seconds since January 1, 1970, adjusted for what PHP is set for the time zone (can be set with date_default_timezone_set).

+2
source

Try setting the GMT time zone.

 date_default_timezone_set('Europe/London'); 
-one
source

I think that if you get the values ​​in the second, then you should use the mktime function, then it will give the correct result. For instance:

 $t=77; echo date("H:i:s", mktime(0,0,$t)); 
-one
source

All Articles