The IntlTimeZone class
(PHP 5.5.0, PECL >= 3.0.0a1)
Введение
Обзор классов
IntlTimeZone
{
/* Constants */
/* Методы */
}Предопределенные константы
IntlTimeZone::DISPLAY_SHORT
IntlTimeZone::DISPLAY_LONG
Содержание
- IntlTimeZone::countEquivalentIDs — Get the number of IDs in the equivalency group that includes the given ID
- IntlTimeZone::createDefault — Create a new copy of the default timezone for this host
- IntlTimeZone::createEnumeration — Get an enumeration over time zone IDs associated with the given country or offset
- IntlTimeZone::createTimeZone — Create a timezone object for the given ID
- IntlTimeZone::fromDateTimeZone — Create a timezone object from DateTimeZone
- IntlTimeZone::getCanonicalID — Get the canonical system timezone ID or the normalized custom time zone ID for the given time zone ID
- IntlTimeZone::getDisplayName — Get a name of this time zone suitable for presentation to the user
- IntlTimeZone::getDSTSavings — Get the amount of time to be added to local standard time to get local wall clock time
- IntlTimeZone::getEquivalentID — Get an ID in the equivalency group that includes the given ID
- IntlTimeZone::getErrorCode — Get last error code on the object
- IntlTimeZone::getErrorMessage — Get last error message on the object
- IntlTimeZone::getGMT — Create GMT (UTC) timezone
- IntlTimeZone::getID — Get timezone ID
- IntlTimeZone::getOffset — Get the time zone raw and GMT offset for the given moment in time
- IntlTimeZone::getRawOffset — Get the raw GMT offset (before taking daylight savings time into account
- IntlTimeZone::getTZDataVersion — Get the timezone data version currently used by ICU
- IntlTimeZone::hasSameRules — Check if this zone has the same rules and offset as another zone
- IntlTimeZone::toDateTimeZone — Convert to DateTimeZone object
- IntlTimeZone::useDaylightTime — Check if this time zone uses daylight savings time
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Поддержка языков и кодировок
- Введение
- Установка и настройка
- Предопределенные константы
- Примеры
- The Collator class
- The NumberFormatter class
- The Locale class
- The Normalizer class
- The MessageFormatter class
- The IntlCalendar class
- The IntlTimeZone class
- The IntlDateFormatter class
- The ResourceBundle class
- The Spoofchecker class
- The Transliterator class
- The IntlBreakIterator class
- The IntlRuleBasedBreakIterator class
- The IntlCodePointBreakIterator class
- The IntlPartsIterator class
- The UConverter class
- Grapheme Функции
- IDN Функции
- IntlChar
- Exception class for intl errors
- The IntlIterator class
- intl Функции
Коментарии
Currently there is no documentation available for IntlTimeZone::parse(), so it took some while to figure out a working example:
<?php
// Example for 32-bit PHP 7.0.30 with Intl version 1.1, ICU version 56.1
// To get the offset of a date including daylight saving time, getRawOffset() is
// not sufficient, getOffset() is needed. And a date is needed to take history
// in to account.
\Locale::setDefault('nl-NL');
$date = '25-03-2018 12:34:56.123456 CEST'; // 3rd of Februari
$timezone = \IntlTimeZone::createDefault(); // = CEST = GMT +02:00
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);
// set UNIX timestamp offset (1970-01-01 00:00:00.000000) and add the timestamp
$cal->set(1970, 0, 1, 0, 0, 0);
$cal->set(\IntlCalendar::FIELD_MILLISECOND, 0); // note: msec, not usec
$cal->add(\IntlCalendar::FIELD_SECOND, $timestamp); // note: no milliseconds
$cal->add(\IntlCalendar::FIELD_MILLISECOND, 124); // hardcode for simplicity
header('Content-type: text/plain');
print 'Date constructed with IntlCalendar: ' . $formatter->format($cal)
. PHP_EOL;
print 'Raw offset by getRawOffset(): ' . $timezone->getRawOffset() . PHP_EOL;
/**
* Function IntlTimeZone::getOffset()
* @link http://icu-project.org/apiref/icu4c/classicu_1_1TimeZone.html#afcbc1c48bf0b453b0123c4cb75d20e96
* @param float $date
* moment in time for which to return offsets, in units of milliseconds from
* January 1, 1970 0:00 GMT, either GMT time or local wall time, depending on
* `local'.
* @param bool $local
* if true, `date' is local wall time; otherwise it is in GMT time.
* @param int &$rawOffset
* output parameter to receive the raw offset, that is, the offset not
* including DST adjustments
* @param int &$dstOffset
* output parameter to receive the DST offset, that is, the offset to be added
* to `rawOffset' to obtain the total offset between local and GMT time. If
* DST is not in effect, this value is zero; otherwise it is a positive value,
* typically one hour.
*/
$rawOffset = NULL;
$dstOffset = NULL;
$timestamp *= 1000.0; // convert unix timestamp from secs to msecs
$timezone->getOffset($timestamp, $local = FALSE, $rawOffset, $dstOffset);
print 'Output of getOffset():' . PHP_EOL . json_encode([
'rawOffset' => $rawOffset,
'dstOffset' => $dstOffset
], JSON_PRETTY_PRINT) . PHP_EOL;
?>