live date time countdown problem from php/mysql database
I have php site and mysql database with date/time field with date/time in future. I need to count down from that future time till now.
Example:
Jimmy 31.12.2011 21:00:00 birthday
Mary 21.11.2011 19:30:00 wedding
Billy 12.03.2012 10:25:30 to NY
......
must show live counter:
Jimmy 123 days 20 hours 15 min 25 sec (and live counting)
Mary 89 days 15 hours 25 min 12 sec (and live counting)
Billy 183 days 12 hours 56 min 15 sec (and live counting)
......
how to do that? I know that on stackoverflow is answer for my qu开发者_JAVA技巧estion, but I haven't find it yet. I used a lot of JavaScripts, try them and find them very nice. But something I do wrong and I don't know what is it. I'm quite new and I'm confused and lost. So, please, help me.
Thanks
DZvonko
the time-span from "now" to a given date and time shouldn't be that hard to calculate ...
so on your javascript part, create a timed event that fires every 1000 msec ... in the event handler re-calculate all timespans (date & time in the future vs local date & time +- time zone offset) and write them to the page ... for an example on timed events have a look here
this approach depends on the clock on the client system ... to fix this error-source you could send the local time to the server, and calculate an offset to the actual server time that gets delivered back to the client together with the page and the dates and times for the countdown ...
精彩评论