这段代码在我的开发服务器上运行得很好,但是当我在另一台服务器上运行它时,它会失败:
$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。
发布于 2012-09-26 12:01:23
好吧,想清楚了。只有PHP 5.3.4+才允许将DateTime对象传递给格式化。对于较早的版本,您需要这样做:
$date = new DateTime('2012-06-01');
$formatter->format($date->getTimestamp());https://stackoverflow.com/questions/12600859
复制相似问题