How do I convert this time format - 1480550400000+

2019-09-14 23:15发布

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?

5条回答
Melony?
2楼-- · 2019-09-14 23:46
$dig_date= 1480550400000+0000;
$date = DateTime::createFromFormat('YmdGis', $dig_date);
  echo $date->format('Y-m-d G:i:s');
查看更多
Summer. ? 凉城
3楼-- · 2019-09-14 23:50

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

Thanks

查看更多
男人必须洒脱
4楼-- · 2019-09-14 23:51

@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/

查看更多
劳资没心,怎么记你
5楼-- · 2019-09-14 23:53

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
查看更多
祖国的老花朵
6楼-- · 2019-09-15 00:00

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
查看更多
登录 后发表回答