Currently there is no documentation available for IntlTimeZone::parse(), so it took some while to figure out a working example:
<?php
\Locale::setDefault('nl-NL');
$date = '25-03-2018 12:34:56.123456 CEST'; $timezone = \IntlTimeZone::createDefault(); print 'Time zone: ' . $timezone->getDisplayName() . PHP_EOL;
print 'DST: ' . ($timezone->useDaylightTime() ? 'DOES' : 'DOES NOT')
. ' happen to this timezone' . PHP_EOL;
print 'Possible DST difference (usec): ' . $timezone->getDSTSavings() . PHP_EOL;
$formatter = new \IntlDateFormatter(
\Locale::getDefault(),
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::MEDIUM,
$timezone
);
$timestamp = $formatter->parse($date);
if (FALSE === $timestamp) {
throw new \Exception('Can not parse date');
}
elseif (is_float($timestamp)) {
throw new \Exception('Y2K38 bug @ 32 bit, please use 64 bit');
}
print 'Date parsed by IntlFormatter::parse(): ' . date('c', $timestamp)
. PHP_EOL;
$cal = \IntlCalendar::createInstance();
$cal->setTimeZone($timezone);
$cal->setLenient(FALSE);
$cal->set(1970, 0, 1, 0, 0, 0);
$cal->set(\IntlCalendar::FIELD_MILLISECOND, 0); $cal->add(\IntlCalendar::FIELD_SECOND, $timestamp); $cal->add(\IntlCalendar::FIELD_MILLISECOND, 124); header('Content-type: text/plain');
print 'Date constructed with IntlCalendar: ' . $formatter->format($cal)
. PHP_EOL;
print 'Raw offset by getRawOffset(): ' . $timezone->getRawOffset() . PHP_EOL;
$rawOffset = NULL;
$dstOffset = NULL;
$timestamp *= 1000.0; $timezone->getOffset($timestamp, $local = FALSE, $rawOffset, $dstOffset);
print 'Output of getOffset():' . PHP_EOL . json_encode([
'rawOffset' => $rawOffset,
'dstOffset' => $dstOffset
], JSON_PRETTY_PRINT) . PHP_EOL;
?>