2

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.

1

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.

2

One: Purpose of the timezone setting in the Admin -> Settings section?
Two: How is the time of the blog saved?

To set your local time, use the wp-admin » Settings - Timezone. As a comment there is saying: "Choose a city in the same timezone as you." For each of the blogpost there are two fields in the database: post_date and post_date_gmt. So whenever you save a post or save a draft of a post, it takes both the time - the local time and the GMT. The local time (post_date) is generated by the setting you make into the Settings - Timezone.

Three: Do the users see their local time into the post-time?

As the post is saved with both of the time (UTC & your local time), so the post will be viewed with the date&time of yours, not theirs, if your Settings do so.

Four: How do I ensure that the custom date field behaves like the WordPress field?

If your custom field is simply <input type="date"/>, I hope it will work with your local time; if that is <input type="datetime"/> then it'll generate an UTC time, if that is <input type="datetime-local"/> then it will allow you to select your local time. But to me both of the last two options are same.
And for your kind understanding: a custom field works like a string. So whatever you input into the field will be the thing you will get from it. Just ensure the thing exactly what you want into the field, it'll return the same. (More on WordPress Custom Fields)

-1

"Your blog’s timezone is set to Coordinated Universal Time, UTC by default, which is in London, UK. If you live in a different area of the world you will likely want to change this option." - http://en.support.wordpress.com/settings/general-settings/

The posts are saved in the UTC format.

Users will see the time the post time as the time the post was created in relation to the blog settings not their local time.

I'm not understanding your final point entirely but you can code what custom fields do using the functions.php file in the wordpress template. - http://codex.wordpress.org/Custom_Fields

http://codex.wordpress.org/Function_Reference/current_time

  • WordPress com documentation doesn't apply to self–hosted installations. The posts are not saved in UTC. While they do have post_date_gmt field, a lot more depends on post_date field, which lacks time zone information altogether and presumes that current time zone setting is used. – Rarst Oct 16 '17 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.