3

这段代码在我的开发服务器上运行良好,但是当我在另一台服务器上运行它时,它失败了:

$formatter = new IntlDateFormatter('en-GB', IntlDateFormatter::LONG, IntlDateFormatter::NONE, 'Europe/London');
var_dump($formatter->format(new DateTime('2012-06-01')));
var_dump($formatter->getErrorMessage() . ' ' . $formatter->getErrorCode());

给我:

bool(false) 
string(14) "U_ZERO_ERROR 0" 

有谁知道为什么?特别奇怪的是它甚至不报告错误(U_ZERO_ERROR 是默认值)。谢谢。

编辑:

为了比较,我在本地得到:

string(11) "1 June 2012" 
string(14) "U_ZERO_ERROR 0" 

我在其他语言环境中也看到了同样的问题,包括en-US.

4

1 回答 1

3

好的,想通了。只有 PHP 5.3.4+ 允许将 DateTime 对象传递给格式。在旧版本上,您需要执行以下操作:

$date = new DateTime('2012-06-01');
$formatter->format($date->getTimestamp());
于 2012-09-26T12:01:23.560 回答