Using Php To Match A Javascript Timestamp
Solution 1:
If you don't need (millisecond) presision, then just divide & Math.floor the javascript's function. So:
time();
and
Math.floor((newDate).getTime()/1000)
should return the same value at the same time.
Solution 2:
What you are looking for is millisecond time in PHP. To accomplish this you need to use a combination of the microtime
function and some multiplication.
microtime
when passed true
as its first parameter will return the current time as the number of seconds since the Unix epoch to the nearest microsecond.
To convert the value into an integer value of the number of milliseconds since the Unix epoch you must multiply this value by 1000 and cast to an integer.
So:
$milliseconds = (int)(microtime(true) * 1000);
Solution 3:
The javascript
getTime() ;
method returns the number of milliseconds since midnight of January 1, 1970 and the specified date.
A php equivalent is
time() * 1000; // not microtime() as I wrongly said earlier.
However they wont match as php does not support millisecond precision it seems.
Post a Comment for "Using Php To Match A Javascript Timestamp"