PHP date with 0 mark

If I do the following:

date("H:i:s", 0);

He returns 01:00:00, but must give 00:00:00.
Could this have anything to do with the time zone of my localhost? (UTC + 1)

If so, how can I fix this?

+3
source share
1 answer

Set the time zone before calling date(). You will use date_default_timezone_set()for this:

date_default_timezone_set('UTC');
echo date("H:i:s", 0);

Look at the action

Do not forget to set it back if you perform operations with the time zone.

Or:

Here's an alternative way to do this with DateTime():

$dt = new DateTime('@0', new DateTimeZone('UTC'));
echo $dt->format('H:i:s');

Look in action

+5
source

All Articles