Domanda

How does PHP get locale GMT datetime display as following:

14/06/2013 10:38 (GMT+8)

Currently my site have this format to display date time like:

14/06/2013 07:01:14 AM GMT+0400

My hosting service provider is in europe, if the user browse my website in Japan (+9:00), how could it show like 14/06/2013 10:38 (GMT+9)?

È stato utile?

Soluzione

The problem with time zones is that your server has no reliable way of determining where your user is. Even the browser has no reliable way to determine this, although it's better placed to guess. The problem is worse when you have to contend with server times that are essentially unknown

So, for your server end, convert all dates and times to UTC. Conduct all server operations in UTC.

When you come to display the times to your user, convert to their local time zone (which you find out by asking them!), or send the times to the browser in UTC and get the browser to do the conversion, or get the browser to provide its timezone when it first connects to the site and use that information to convert output times.

Of these, the first option is the most reliable, but might not be acceptable to your site. Options 2 and 3 rely on configuration data set by the user local to the browser.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top