How do I convert this time format - 1480550400000+

2019-09-14 23:23发布

问题:

I am trying to convert this time format - 1480550400000+0000 in Y/m/d date format using php date('Y/m/d',1480550400000+0000); but its not working. How can I make it work?

回答1:

You timestamp has microseconds, so first remove it.

<?php
$timestamp = 1480550400000+0000;
$timestamp = intval($timestamp/1000);
$date = date("Y/m/d", $timestamp);
echo $date;

output: Check the live demo.

ei@localhost:~$ php test.php
2016/12/01


回答2:

$dig_date= 1480550400000+0000;
$date = DateTime::createFromFormat('YmdGis', $dig_date);
  echo $date->format('Y-m-d G:i:s');


回答3:

Please note that the second parameter should be time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). Looks like you have entered milliseconds instead.

PHP date()

string date ( string $format [, int $timestamp = time() ] )

timestamp

The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

Try this:

echo date('Y/m/d',1480550400+0000); // 2016/11/30


回答4:

Solved I just divided this with 1000. $date = date("Y-m-d", $timestamp/1000); and it worked

Thanks



回答5:

@Symplifys try this:

<?php
    $date = date("Y-m-d", "1480550400000+0000");``
    echo $date;
?>

Remember to put timestamp in double quotes.

Try this code at http://phpfiddle.org/