0

I'm eceiving an unknown datetime format from a JSON file:

"expectedStartTime":1431469800000

anyone recognize this format, and can guide me into how to convert it to "YYYY-MM-DD H:i:s" format?

2
  • 3
    Probably milliseconds from the epoch Commented May 12, 2015 at 19:26
  • 1
    so it should be date("Y-m-d H:i:s", ($expectedStartTime/1000)) Commented May 12, 2015 at 19:39

2 Answers 2

1

Expecting it is a timestamp in milliseconds it should work like this:

$json = '{"expectedStartTime":1431469800000}';

$arr = json_decode($json,true);

echo date("Y-m-d H:i:s", $arr['expectedStartTime']/1000);

The given value will output:

2015-05-13 00:30:00
Sign up to request clarification or add additional context in comments.

1 Comment

It should be noted that this is only correct in the UTC+2 timezone. I guess you live in Europe somewhere. If the OP needs to write it as UTC to a database, they should probably use the DateTime object or make sure their PHP timezone is UTC inside their application.
0

It is a Java style unix timestamp which is miliseconds from the epoch. You can divide by 1000 and treat it as a normal Unix timestamp like this.

$expectedStart = new DateTime("@" . ($time/1000));
print $expectedStart->format("Y-m-d H:i:s");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.