Date, Time, and Timezones

I am a bit confused about using dates/times along with timezones in WordPress. I have the following questions:

  1. What is the purpose of the timezone setting in the Admin -> Settings section?

  2. Assume current time in GMT is 20:00, and Assume I am in EST (so it is 16:00 in EST time), how is the time of the blog saved?

  3. Assume a reader is reading the post, and he/she is located in Turkey. So their local time is 23:00, do they see 23:00 as the post time?

  4. Assume I am using a custom post type, and I am having an extra date/time field for other date information. How do I ensure that the custom date field behaves as the WordPress field?

I apologize for those basic questions, but I really need your help explaining those.

3 Answers
3

What is the purpose of the timezone setting in the Admin -> Settings section?

Since WordPress handles time zone on its own (separately from native PHP functionality) that is where the setting made and result is stored in options.

Whenever anything that works with timezones needs to happen, the time zone setting is retrieved and used in calculations/output.

Assume current time in GMT is 20:00, and Assume I am in EST (so it is 16:00 in EST time), how is the time of the blog saved?

There are two date fields in database for each post. They both store date without timezone information, post_date is presumed to be in current timezone setting and post_date_gmt is presumed to be in UTC.

Unfortunately much of WP code relies on post_date one, which causes numerous bugs. For example if the time zone setting is changed all the past posts now have wrong time since they had been stored in a time zone different from now current one.

Assume a reader is reading the post, and he/she is located in Turkey. So their local time is 23:00, do they see 23:00 as the post time?

No, WP processes and output times server–side, in context of its settings. Any client–side settings are irrelevant unless purposely implemented, which is relatively rare.

Assume I am using a custom post type, and I am having an extra date/time field for other date information. How do I ensure that the custom date field behaves as the WordPress field?

Don’t. The way WP does it is a very ancient and very custom mess, with serious amount of bugs.

Any clean solution should operate with strict unambiguous date storage, such as Unix timestamps. Specific choice depends a lot on which would need to be done with the information and if human readability on storage level is important.

Leave a Comment