4

I'm trying to do something incredibly simple - convert a timestamp to a string in php with the date() function.

Code is as follows:

$test = date('d/m/y','1407974400000');
echo $test;

I expect the answer to be 14/8/14.

If I check on http://www.epochconverter.com/ that also gives this answer.

Yet the output produced from the above PHP is

07/12/86

I'm pretty sure I'm doing something completely stupid here - any able to help?

Thanks,

Chris

3
  • time() for me currently outputs 1408013482. You've got 3 digits too many. You should use seconds. Commented Aug 14, 2014 at 10:52
  • Did you get that value from javascript? Javascript timestamps are different to PHP for some reason I have yet to totally understand. They tend to be in micro seconds and if its from a smart phone it gets even weirder as android and apple js date timestamps are also bigger but also different to each other. There be Dragons. Commented Aug 14, 2014 at 10:55
  • Yes I did, the wider script is part of an AJAX call initiated by JS. I didn't know there were those differences so will look out of them. Thanks. Commented Aug 14, 2014 at 10:58

2 Answers 2

4

You had 3 zeros more, use seconds instead of milliseconds:

$test = date('d/m/y','1407974400');
echo $test;
Sign up to request clarification or add additional context in comments.

Comments

1

You should use "seconds" not "milliseconds" on date function as timestamp.

$test = date('d/m/y','1407974400');
echo $test;

1 Comment

Thank you very much - I knew it was something stupid.

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.