Epoch to date

I’ve been testing some dates between AS3 and PHP. I want to upload them into a database so formating into mySQL format too. To make it straightforward I passed milliseconds between AS3 and PHP. My fun started when I tried to convert it to a date in PHP 5.3.29
The date I stared with in AS3: Fri Oct 28 2016 17:45:13 (my local time)
In milliseconds thats: 1477669513556
My test code:

if    (is_numeric($testDate)){
echo "Milliseconds: " .$testDate ."\n";
echo "DATE: " .date('Y-m-d H:i:s', $testDate) ."\n";
}

The result I got was
Milliseconds: 1477669513556
DATE: 1976-05-12 16:42:12

?
Can someone kindly explain to me where I or PHP are going wrong???

The doc for time() says "Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). ", so if you’re passing in milliseconds to a function that expects a time based on the number of seconds, isn’t that going to cause a problem?

The way I usually look at translating value representations is to compare the two values - so what happens if you display the raw value of time() for the date/time example you use above?

@droopsnoot Thanks for your input, I’ve not been using time() but Doh! you were right… I was so rapped up in coding that I negated to realise that date() in PHP requires seconds…what a stupid oversite… Thanks

1 Like

I saw that you don’t use time() directly, but the second parameter of the date() function is a time() value, that’s what I was getting at. Glad it’s helped.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.