Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php messageformatter

MessageFormatter does not work with DateTime instances as parameters in PHP < 5.5. Instance will be converted to timestamp with value 0 (e.g. 1970-01-01) and following Notice will be raised: „Object of class DateTime could not be converted to int“. You have to manually convert the instance to timestamp in these old PHP versions.

<?php
$datetime = new DateTime();
if (PHP_VERSION_ID < 50500) { // PHP < 5.5 needs conversion to timestamp
   MessageFormatter::formatMessage('en_US', 'Today is {0, date, full}.', array($datetime->getTimestamp()));
} else {
   // current code
   MessageFormatter::formatMessage('en_US', 'Today is {0, date, full}.', array($datetime));
}
?>
Source by www.php.net #
 
PREVIOUS NEXT
Tagged: #php #messageformatter
ADD COMMENT
Topic
Name
2+1 =