im writing a small calendar based on php and jquery which has the a function to calculate the time difference and display a popup 15 minutes before.
Can some one tell me how can i calculate the time difference in minutes and popup 15 minutes before.
my time is saved as
18-07-2012 15:13:54
jsBin demo
Code explanation:
To get the remaining time I’ve done a millisecond comparison of the
phpreturned time in milliseconds from Jan. 1 1970and the current time in
msfrom Jan 1 1970 – subtracting the two values and getting the milliseconds difference. To calculate that difference in minutes I’ve just done:The trick was to get the right time format and to revert your (php) returned time to that format too.
The default format looks like:
MONTH/DAY/YEAR HOURS:MINUTES:SECONDSTo convert the php returned time
'19-07-2012 03:00:00'to that one, I used:which returns:
07/19/2012 03:00:00and now we can compare it to the current time e.g.:To retrieve the
msfrom your converted php time we can use:and for the current time we just take:
Now having our two milliseconds values we can simply subtract them to get the remaining time: