Possible Duplicate:
How to sync a javascript countdown with server time
How can I get the to calculate the difference between the server side time and the client side time and then display it in my view , which is a PHP page .
Let me make this a bit clear. I have a time data for a particular cricket match to start which is stored in the database . Now, I want to display the difference between this time and the time in the client browser in my view which is a PHP page. I can understand that I need to write a javascript function for this , but how can I call this function from my PHP code ,and again I have to display the difference in my view.
I am confused about this.
Send (new Date()).getTime() from javascript to the php script, and use the time() function in php.
This should be accurate down to the time it takes the client to talk to your server.
Write your date in php to a hidden input on your page. Store it in a format like:
YYYY/MM/DD hh:mm:ss
. Load that date by passing the value of the hidden field to the Date constructor:Get the current date just by calling the Date constructor with no arguments:
Get the difference in milliseconds by subtracting the dates:
You can then parse the milliseconds manually, or convert to a date and extract the parts of the date to get the difference:
i do not know if it is the correct methods.. but you can do is
and in the setSessionData just use the value and set session .. and when showing the details get the match times
use mktime() to calculate the $matchTime
date.js is pretty handy for date calculations and can parse/display dates in various formats.