Question

i want to pass php datetime to javascript using this code:

var x="<?php echo strtotime($uEvents['start']);?>";


but the value of unix timestamp is different (database value is "2014-03-25 08:36:15")

echo strtotime($uEvents['start'])] ==> 1395711375<br/>
var x ==> 1395711287


i've search about this difference, but it seems not because javascript is milliseconds and php is in seconds

Was it helpful?

Solution

It looks like this problem caused by difference in time between server and client (which is about 1.5 minutes).

If you want client to get the same time as server pass try this:

var d = new Date("<?php echo $uEvents['start']; ?>");  //Date constructor can
                                             //parse datetime passed as a string

console.log(d.toString());   //this will output time you need

You can also get millisecond timestamp:

var timestamp = d.getTime();

as well as hours, minutes, and seconds:

var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top