0

I need accurate time which my website should be able to access thru internet for synchronization. How can I do it? Should I ping some time server(by the way which one?) every 30 minutes? Then how will I be able to apply DST settings to get local times of any where in world? I'm having a shared account, not sure if my site will be able to access time server on internet.

user5858
  • 1,082
  • 4
  • 39
  • 79

1 Answers1

1

To my knowledge, this is usually something that is managed by the OS. Depending on the scripting language you use, there is almost always a way to get the current timestamp.

EDIT: Mar 09 2011

If you are a glutton for punishment, you could go about trying to implement (or using a component that implements) the NTP Protocol. Like I said in my original post, this is usually something that is handled by the OS / Domain Controller and is not something I know a whole lot about.

With regards to timezones, the best way to handle this is to keep track of time on your website internally using the Universal Time Coordinate (UTC). The vast majority of scripting languages have functions to retrieve the current UTC. Converting from local time to UTC and back can be done using Olson Timezones. This is a database of all changes for all timezones around the world. If users login to your website, they should be required to specify a timezone. Otherwise, you can "guess" which timezone to use based some anonymous data the user sends over (IP Address, Accept Language, etc).

You mentioned you have a shared account. What OS / Scripting language are you using or planning to use?

Oddthinking
  • 24,359
  • 19
  • 83
  • 121
dana
  • 17,267
  • 6
  • 64
  • 88
  • OS can't guarantee accuracy. I want to use international time server. – user5858 Mar 09 '11 at 08:14
  • @user543087 - please see my updated answer with feedback to your comment. – dana Mar 09 '11 at 16:44
  • I want latest accurate time in every 10 minutes. From which server can I sync? I'll be using PHP on unix platform. – user5858 Mar 11 '11 at 04:57
  • If you are using Linux, the most straight forward way to get the system clock in sync is probably going to be via the NTP Daemon (http://www.eecis.udel.edu/~mills/ntp/html/ntpd.html). You mentioned its a shared account, so I am not sure whether you will have access to install / configure such an option. As far as a server list, you can check out http://www.pool.ntp.org/ or http://tf.nist.gov/tf-cgi/servers.cgi. Lastly, since you are using PHP it is worth mentioning that the language supports a variety of timezone functions http://www.php.net/manual/en/book.datetime.php. – dana Mar 17 '11 at 05:42