如何使用 php 转换此时间格式 - Y/m/d 日期格式中的 1480550400000+0000

How do I convert this time format - 1480550400000+0000 in Y/m/d date format using php

我正在尝试使用 php date('Y/m/d',1480550400000+0000) 将此时间 format - 1480550400000+0000 转换为 Y/m/d 日期格式;但它不工作。我怎样才能让它发挥作用?

请注意,第二个参数应该是自 Unix 纪元(1970 年 1 月 1 日 00:00:00 GMT)以来的 秒数 的时间。看起来你输入的是毫秒。

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().

试试这个:

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

@Symplifys 试试这个:

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

记得把时间戳放在双引号里。

http://phpfiddle.org/

试试这个代码

你的时间戳有微秒,所以先把它去掉。

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

输出:检查live demo.

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

已解决我只是将其除以 1000。 $date = date("Y-m-d", $timestamp/1000);并且有效

谢谢