0

I have a timestamp of "1377592503467" stored in a variable and when I pass it to php's date() function, it returns a value of "1935-05-26 03:04:11". Hopefully I am missing something obvious; below is my code. The timestamp represents 2013-08-27 15:57:45 but that's not what is being returned.

$date = "1377592503467";
$formattedDate = date("Y-m-d h:i:s", $date);

Thank you.

0

1 Answer 1

7

Looks like that timestamp is in milliseconds, not seconds as PHP uses them.

Do date(..., $date / 1000).

Sign up to request clarification or add additional context in comments.

5 Comments

I'm not sure it's exactly in milliseconds, since (GMT+04): 2013-08-27 08:35:03 is a corresponding date for 1377592503
@Alma True, but at least it gets you into the right ballpark. I'm not aware of a generally applicable timestamp format which in addition has a few hours of skew, so I'd just err on the side of the OP providing incorrect information. :)
I wanted to ask in comment why OP providing timestamp larger than 2^31-1 (i.e. max for signed longint) - but since there's high rated answer, it seems, you're correct.
I don't know how the OP got that timestamp, but the microsecond explanation makes more sense. See this.
Thanks deceze! Appreciate the help from all. I used the /1000 as a solution.

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.