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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 04:22:28

问题


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/



来源:https://stackoverflow.com/questions/41583209/how-do-i-convert-this-time-format-14805504000000000-in-y-m-d-date-format-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!