I often need to display information based on or influenced by a user's actual local time which differs across time zones. Is there a reliable way of getting a user's current time and/or timezone?
Key Issues:
- Server-side code is based on the website host or user's ISP
- Client-side code is based on the user's system clock which is too easily manipulated
Key questions:
- Is it necessary to pinpoint a user's geo-location?
- Can the ISP time be an accurate guide?
- Users OS clocks can vary or be modified by users?
Examples:
Countdown:
Only 1 hour, 3 minutes, 56 seconds to go!
Issue: seconds to go based on what; The user's OS clock, the hosts server time (plus or minus offset), ISP system time. This is easy if the clock finishes at the same time for all timezones, but trickier if it's a countdown to something like midnight in the user's local time zone)
Edit log
Item posted at 3:03pm (10 seconds ago)
Issue: "10 seconds" is calculated regardless of user, the time is adjusted to match the user's time zone.
Opening times:
This restaurant is open now until midnight (AEST).
Issue: Giving a time such as midnight can be calculated by offsetting from the server-side but using psudo times such as now, in 2 hours is based on the user's time.
PHP: using time()
outputs the server time. This can be offset depending on the user's timezone.
JavaScript: using Date()
outputs the user's computer clock time which is too easily manipulated.