Monday, December 4, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  103] [ 2]  / answers: 1 / hits: 32296  / 15 Years ago, thu, may 14, 2009, 12:00:00

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?



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.

More From » php


In short no.

I would suggest using server side time, and have the ability for the user to choose their time zone.

You could possibly calculate default time zones for users based on heuristics around their IP address, but this is open to error.

You should be able to extract client side time zone information through javascript / Ajax, but as with the time itself this is also open to error.

My recommendation: Let users choose their time zone with a sensible default based on where you expect your users to be.

[#99539] Saturday, May 9, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 254
Total Questions: 92
Total Answers: 89

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago