0

I have looked every where for a solution to convert 1357133639816 milliseconds into dd-mm-yyyy h:m:s using PHP 5.3 and also convert current server time into the same millisecond format as given above.

This value is an extract from an SMS on android with display time value of 02-Jan-2012 07:03 PM

I have tried hard to find and test as many codes available online.

PS - http://codepad.org helped in quick execution of any test code (if you may like to test urs before posting).

hakre
  • 193,403
  • 52
  • 435
  • 836
Viktor Tango
  • 453
  • 9
  • 19
  • I had seen that link and could not derive any solution for my query from it. Also, the value mentioned here for result validation. I did generic searches all along. But thanks. – Viktor Tango Jan 03 '13 at 19:02
  • 2
    @Vishal: Really, [the code given in that question didn't work for you?](http://codepad.org/3o8WSTzi) (ps. It's 2013 now.) – Ilmari Karonen Jan 03 '13 at 20:07

1 Answers1

7

Just like this question and its answers say, you simply need to convert the timestamp to seconds by dividing it by 1000 and then use date() to format it:

$mil = 1357133639816;
$seconds = $mil / 1000;
echo date("d-m-Y H:i:s T", $seconds);

Output:

02-01-2013 13:33:59 UTC

To change the output to your local timezone, you can use date_default_timezone_set():

date_default_timezone_set("Asia/Calcutta");

$mil = 1357133639816;
$seconds = $mil / 1000;
echo date("d-m-Y H:i:s T", $seconds);

Output:

02-01-2013 19:03:59 IST
Community
  • 1
  • 1
Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153