I noticed that IntlDateFormatter()
function returns wrong timestamp in comparison to same type of output from DateTime()
function.
PHP:
$formatter = new IntlDateFormatter(
'en_GB',
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Europe/London',
IntlDateFormatter::GREGORIAN,
'dd MMMM YYYY, HH:mm'
);
$now = new DateTime('01-03-2023 17:00');
echo '<b>DateTime() String:</b> ' . $now->format('d F Y, H:i') . '<br/>';
echo '<b>IntlDateFormatter() String:</b> ' . $formatter->format( $now ) . '<br/><br/>';
echo '<b>DateTime() Timestamp:</b> ' . $now->getTimestamp() . '<br/>';
echo '<b>IntlDateFormatter() Timestamp:</b> ' . $formatter->parse( $formatter->format( $now ) );
OUTPUT:
DateTime() String: 01 March 2023, 17:00
IntlDateFormatter() String: 01 March 2023, 17:00
DateTime() Timestamp: 1677690000
IntlDateFormatter() Timestamp: 1672074000
As is visible above, IntlDateFormatter()
returns good string, but a bad timestamp value from the same source. Why is that happen?