Jack Sleight
Jack Sleight

Reputation: 17118

PHP IntlDateFormatter->format() returns false

This code works perfectly on my development server, but when I run it on another server, it fails:

$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());

Gives me:

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

Does anyone know why? It's particularly odd that it doesn't even report an error (U_ZERO_ERROR is the default). Thanks.

Edit:

For comparison, locally I get:

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

I'm seeing the same issue with other locales as well, including en-US.

Upvotes: 3

Views: 1350

Answers (1)

Jack Sleight
Jack Sleight

Reputation: 17118

OK, figured it out. Only PHP 5.3.4+ allows DateTime objects to be passed to format. On older versions you need to do:

$date = new DateTime('2012-06-01');
$formatter->format($date->getTimestamp());

Upvotes: 3

Related Questions