-5

can anyone convert me this timestamp into readable date 1444782970870 in php ?

I have tried date('Y-m-d', '1444782970870') but returns Nov 30, 7086

The result should be Oct 14, 2015 i tried on Unix timestamp converter

before you answer, please try it first.

Marlon Buendia
  • 342
  • 1
  • 6
  • 19
  • @PaulCrovella please read first – Marlon Buendia Oct 13 '15 at 03:27
  • 2
    Why are you wrapping your timestamp in strtotime? Just pass that timestamp as 2nd parameter without strtotime –  Oct 13 '15 at 03:36
  • 1
    Also what @devinhoward said about too many digits might matter. Try removing the last 3 –  Oct 13 '15 at 03:39
  • @Terminus i removed the strtotime, its my mistake. why remove last 3 digits? the data is from API. – Marlon Buendia Oct 13 '15 at 05:40
  • My mistake. You can leave it and it won't do anything. See this question/answer http://stackoverflow.com/questions/17909871/getting-date-format-m-d-y-his-u-from-milliseconds. –  Oct 13 '15 at 11:15

1 Answers1

2

You've got too many digits; you're including microseconds, but PHP wants seconds since 1970.

date_create_from_format('U', (substr('1444782970870', 0, 10)))->format('Y-m-d');

works for me

http://php.net/manual/en/datetime.createfromformat.php

Devin Howard
  • 675
  • 1
  • 6
  • 17
  • Rather than using substr, it is probably best to simply divide the timestamp by 1000, Although unlikely, it will break if a larger timestamp is ever given to the script if you use substr. – ThePengwin Oct 13 '15 at 05:02