I am a bit confused about using dates/times along with timezones in WordPress. I have the following questions:
-
What is the purpose of the timezone setting in the Admin -> Settings section?
-
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?
-
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?
-
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.
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.
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 andpost_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.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.
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.
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
andpost_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.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.
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)
“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