Convert unix timestamp to human readable date in PHP?

I have a timestamp value from PHP: 1188604800000

When I format the time for reading by a person as follows:

 date("m/d/Y", 1188604800000) 

He prints:

 05/21/39635 

If I put the number in the Timestamp Unix online converter, I get:

 Sat, 01 Sep 2007 00:00:00 GMT 

What am I doing wrong?

+6
source share
2 answers

PHP uses seconds based timestamps, so divide 1188604800 by 1000 , and you're good.

 php> echo date('Ym-d', 1188604800000/1000); 2007-09-01 
+13
source

I had a problem with my date being one day off and I had to manually set the default timezone to match my location using

 <?php date_default_timezone_set("Australia/Perth"); ?> 

A list of reference time zones can be found here - http://www.php.net/manual/en/timezones.php

(I have not enough comments to comment on whether someone can merge this with the actual answer?)

+6
source

Source: https://habr.com/ru/post/913646/


All Articles