Jump to content

Getting The Time


jimfog

Recommended Posts

I am wondering what it would be the best way to get the time, using php or javascript. On second thought though. Is in it correct or not that php gives the time of the server(which location might be in another part of the world). So, if my logic is correct, using javascript is the preferred way if we want to get the time of the place the user resides. All of these, because I want the time displayed in the user's screen, it is a feature of a web application i am developing.

Link to comment
Share on other sites

yes. javascript will use the clients time. php will use the servers time. it would not be unexpected for them to be different given the relative locations of user and server.

Link to comment
Share on other sites

If you want to show up client's time javascript will be probably your choice. though there may be such a situation where js is not supported or disabled. so ih those case it will not work. you can use php to evaluate time. php by default shows the server timezone time but you can make it to show the user timezone time also. either you can send timezone data using javascrip (which also need activeness of js in browser) or you can use IP based timezone detection (eg. geoip) to determine timezeone of it (geoip is not always accurate though) you can use js approach first and a fallback to geoip based timezone to work it appropiately

Link to comment
Share on other sites

You can also get people to tell you their timezone when they sign up, then you can use PHP to retrieve their local time. This is how many web applications, including this forum, work.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...