Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP int to date problem

Take a look on the code below:

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

It returns

21:01:17

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

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

How can this problem be fixed?

like image 864
Paulo Bueno Avatar asked Feb 28 '23 23:02

Paulo Bueno


2 Answers

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

date_default_timezone_set('GMT');
$t=77;
echo date("H:i:s", $t);
like image 187
Atli Avatar answered Mar 05 '23 19:03

Atli


The second argument to date() is a unix timestamp - in other words it is a number of seconds since Jan 1, 1970, adjusted to what PHP is set to for a timezone (can be set with date_default_timezone_set).

like image 34
tloach Avatar answered Mar 05 '23 19:03

tloach