开发者

DateTimeZone error: Unknown or bad timezone

I am trying to run this script:

<?php
$d = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$time = $d->format('H:i');

echo $time;
?>

but I got this error:

Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct() [<a href='function.DateTimeZone---construct'>function.DateTimeZone---construct</a>]: Unknown or bad timezone (Asia/Kolkata)

Though it works well for Asia/Dacca for example. What could be the pr开发者_StackOverflow中文版oblem and how to fix it?


And welcome to StackOverflow! If you haven't already make some time to read the FAQ.

I tried your example and it worked for me with PHP 5.3.1 and "Olson" Timezone Database Version 2009.18 .

You should do a phpinfo() and see what time zone DB version you have and if it's older update it. You can see in this list that the most recent version, 2011.1, has Asia/Kolkata.


Try this for fun.

$timezones = array('Europe/London', 'Mars/Phobos', 'Asia/Kolkata');

foreach ($timezones as $tz) {
    try {
        $mars = new DateTimeZone($tz);
    } catch(Exception $e) {
        echo $e->getMessage() . '<br />';
    }
}


I've got same problem when try to run webserver in CHROOT jail. In this case chrooted dir can not contain Linux timezone files. If it's your case and you have access to webserver files simple copy all files to chroot jail:

For CentOS it's

cp -R /usr/share/zoneinfo/ /MY_CHROOT_DIR/usr/share/


PHP timezone database has been updated in version 5.3. Try installing that and try again

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜