开发者

Drupal timezone information

In my drupal installation I can get the offset from UTC in seconds to the timezone I specified in the admin panel using

variable_get('date_default_timezone', 0)

However, now that we have daylight-saving-time, the time I get is always off by one hour. Is there a way to retrieve the actual timezone string from Drupal, as "Europe/B开发者_C百科erlin" for example?

The reason is, that I have to use this with Zend Framework's Zend_Date, but Drupal does not set the PHP default timezone, as

echo date_default_timezone_get();

gives me System/Localtime.


The variable date_default_timezone should always be right.

For example, in France, it should be 3600 in winter (UTC+1), and 7200 in summer (UTC+2).


The thing is the value it contains will not change by magic : there is a cron hook called date_timezone_cron that must be run in order to change that when it's required (quoting) :

Update the site timezone offset when cron runs.
This is to make sure that modules that rely on the timezone offset have current information to process.


After that, if you need the name of the current timezone -- the one selected in the admin section -- there is probably another row in the variable tables for that.

You could find it with an SQL such as :

select *
from variable
where name like '%timezone%';

It will most likely return several rows ; but one of them should be the obvious choice.

Judging from the source code of date_timezone.module, I would bet on a variable called date_default_timezone_name.


I found the solution:

date_default_timezone is only set, when custom user timezones are disabled in the admin panel! Make sure that you check off that option.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜