欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

网站的时区 站点的时区 Date Locale & Time Zone settings

Date Locale & Time Zone settings

 

 

Last updated 4 November 2014. Created on 10 April 2010.
Edited by arpitrbatigolixchadhesterMaksym KozubLog in to edit this page.

Locale Settings

 

The local settings can be found at:

  • admin/settings/date-time in Drupal 6
  • admin/config/regional/settings in Drupal 7.

Default time zone

 

Sets the default time zone for the website. Think of this setting as the time zone where the organization is based. When anonymous users visit the site, time fields displayed for them will be converted to this time zone.

User-configurable time zones

 

Determines if individual users can set their own default time zone. When the user is logged on, this effectively over-rides the above "Default time zone" setting.

First day of week:

 

Sets the desired first day of week. Mostly affects calendar grid displays, but also affects date-browser output when vieing dates by week. For most US/english sites, this should be set to Sunday. Monday is also frequently used in countries that follow the ISO 8601 date standard. Also, Saturday is common among Gulf Cooperation Council countries. (see http://en.wikipedia.org/wiki/Seven-day_week#Week_number for details)

Use ISO-8601 week numbers

 

For USA/Canada/Australia as well as many Middle East countries, week numbers DO NOT follow the ISO-8601 standard, and this option should be unchecked (unchecked is the default behavior).
To fully comply with the ISO-8601 standard for date & time, this option should be checked & First day of week should be set to Monday. This is common for much of Europe & Asia.

Time Zone settings unique to each date field instance

 

Time zone settings can be found at: /admin/content/node-type/[machine_name_of_node-type]/fields/field_[machine_name_of_field]

Time zone handling

 

There are 5 different options for field Time zone handling:

  1. Site's time zone - When entering data into the field, the data entered is assumed to be in the site's time zone. When the data is saved to the database, it is converted to UTC. When retrieved from the database, the data is converted to the Site's time zone for anonymous users or the User's time zone for logged in users when User-configurable time zones is enabled.
  2. Date's time zone - With this option enabled, the date field adds a select box to explicitly specify the time zone for the date entered. When the date is saved to the database, it is not converted & the time zone information is saved with the date. When retrieved from the database, no conversion is performed and the date is displayed exactly as entered.
  3. User's time zone - When entering data into the field, the data entered is assumed to be in the user's time zone. When the data is saved to the database, it is converted to UTC. When retrieved from the database, the data is converted to the Site's time zone for anonymous users or the User's time zone for logged in users when User-configurable time zones is enabled.
  4. UTC - When entering data into the field, the data entered is assumed to be in UTC time zone. When the data is saved to the database, it is converted to UTC (e.g. no conversion necessary). When retrieved from the database, the data is converted to the Site's time zone for anonymous users or the User's time zone for logged in users when User-configurable time zones is enabled.
  5. No time zone conversion - The date entered is not converted when saved to the database. When retrieved from the database, the data is NOT converted and is displayed exactly as entered.

Switch from "No time zone conversion" to "Date's time zone"

 

If you start off without a time zone, but then realize that you need one at a later date, it's possible to switch from "No time zone conversion" to "Date's time zone" even though the UI doesn't recommend it.

Perform the switch in the field settings, but once done, execute the following query:
UPDATE content_field_foo SET field_foo_timezone = 'UTC'

...where content_field_foo is the table containing the date field data, and field_foo_timezone is the time zone column. For each field instance, this will set a proper time zone where there wasn't one before. Without doing this, your dates will show up with different times depending on the site's time zone and your users' time zones.

You may then edit the time zones to something specific other than UTC on each node's edit page.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

 

dpatte’s picture

 

I am running Date 6.x-2.9, and using Date's time zone, but it seems to convert the datetime to UTC on storage into the database, and convert it back to the Date's time zone on redisplay. The above documentation instead says that no conversion is done in the database. Is this in error in the documentation, or when was the functionality changed?

ultimike’s picture

 

I'm using Date 7.x-2.6, and I agree with @dpatte's comment above. With Date fields that have their timezone handling set to "Date's time zone", it appears that the value stored in the database is UTC, not the local time.

I believe the relevant portion of the documentation above should be re-written as:

Date's time zone - With this option enabled, the date field adds a select box to explicitly specify the time zone for the date entered. When the date is saved to the database, it is converted to UTC and the time zone information is saved with the date. When retrieved from the database, the date is displayed exactly as entered.

I'm 95% sure about this - I'm happy to update the documentation once someone chimes in to confirm that we're on the right track.

Thanks,
-mike

dpatte’s picture

 

Hi,
I am using Drupal 7.22 version. I added date and time field (pop-up calender) in content type to get input values from user.

The problem is, when content type save, its getting stored correctly in DB but its displayed wrong time value in page.
I already set Default time zone. Still its display wrong time.

Also I am unable to find setting for "No time zone conversion ".

Any one have any idea?

Help appreciated.

Thanks,

dpatte’s picture

 

In Drupal 6, in addition to adding time zone column I had to add field_foo_offset in order for Calendar Views to show updated nodes.

For example if your Content Type have From and End dates you need to make changes to your nodes like this:

UPDATE `content_type_foo` SET `field_foo_timezone`='UTC';
UPDATE `content_type_foo` SET `field_foo_offset`= '0'; 
UPDATE `content_type_foo` SET `field_foo_offset2`= '0'; 

 

As other mentioned, keep in mind that once you switch from No time zone conversion to Date's time zone, Drupal will treat existing times as they are in UTC and not your local or site time zone. To adjust times as they were entered in UTC you need to add or subtract hours depending on difference between original times and UTC.

Something like this, just make sure to exclude nodes with all day dates:

UPDATE `content_type_foo` SET `field_foo_value` = DATE_SUB(`field_foo_value`, INTERVAL 2 HOUR)
来自 https://www.drupal.org/node/767182

普通分类: