当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTime::getTimeZone方法代码示例

本文整理汇总了PHP中DateTime::getTimeZone方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::getTimeZone方法的具体用法?PHP DateTime::getTimeZone怎么用?PHP DateTime::getTimeZone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTime的用法示例。


在下文中一共展示了DateTime::getTimeZone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setDateTime

 /**
  * Updates the Date and Time.
  *
  * @param DateTime $dt
  * @param int $dateType
  * @return void
  */
 public function setDateTime(DateTime $dt, $dateType = self::LOCALTZ)
 {
     switch ($dateType) {
         case self::LOCAL:
             $this->setValue($dt->format('Ymd\\THis'));
             $this->offsetUnset('VALUE');
             $this->offsetUnset('TZID');
             $this->offsetSet('VALUE', 'DATE-TIME');
             break;
         case self::UTC:
             $dt->setTimeZone(new DateTimeZone('UTC'));
             $this->setValue($dt->format('Ymd\\THis\\Z'));
             $this->offsetUnset('VALUE');
             $this->offsetUnset('TZID');
             $this->offsetSet('VALUE', 'DATE-TIME');
             break;
         case self::LOCALTZ:
             $this->setValue($dt->format('Ymd\\THis'));
             $this->offsetUnset('VALUE');
             $this->offsetUnset('TZID');
             $this->offsetSet('VALUE', 'DATE-TIME');
             $this->offsetSet('TZID', $dt->getTimeZone()->getName());
             break;
         case self::DATE:
             $this->setValue($dt->format('Ymd'));
             $this->offsetUnset('VALUE');
             $this->offsetUnset('TZID');
             $this->offsetSet('VALUE', 'DATE');
             break;
         default:
             throw new InvalidArgumentException('You must pass a valid dateType constant');
     }
     $this->dateTime = $dt;
     $this->dateType = $dateType;
 }
开发者ID:RainyBlueSky,项目名称:PHProjekt,代码行数:42,代码来源:DateTime.php

示例2: formatted_time

function formatted_time($datetime_str = 'now', $timestamp_format = NULL, $timezone = NULL)
{
    $tz = new DateTimeZone($timezone ? $timezone : date_default_timezone_get());
    $time = new DateTime($datetime_str, $tz);
    if ($time->getTimeZone()->getName() !== $tz->getName()) {
        $time->setTimeZone($tz);
    }
    return $time->format($timestamp_format);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:formatted_time.php

示例3: assertDatesEqual

 /**
  * Assert that two dates are equal.
  */
 protected function assertDatesEqual(DateTime $dt1, DateTime $dt2, $msg = "Expected DateTime1 == DateTime2: %s")
 {
     if ($dt1 != $dt2) {
         if ($dt1->getTimeZone()->getName() != $dt2->getTimeZone()->getName()) {
             $this->fail(sprintf($msg, "Timezones were not the same."));
         } else {
             $this->fail(sprintf($msg, "Timezones were the same, but date values were different."));
         }
     }
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:13,代码来源:PropelDateTimeTest.php

示例4: setDateTime

 /**
  * Sets the property as a DateTime object.
  *
  * @param \DateTime $dt
  * @return void
  */
 public function setDateTime(\DateTime $dt)
 {
     $values = array();
     $tz = null;
     $isUtc = false;
     $tz = $dt->getTimeZone();
     $isUtc = in_array($tz->getName(), array('UTC', 'GMT', 'Z'));
     if ($isUtc) {
         $value = $dt->format('Ymd\\THis\\Z');
     } else {
         // Calculating the offset.
         $value = $dt->format('Ymd\\THisO');
     }
     $this->value = $value;
 }
开发者ID:zhuomingliang,项目名称:webmail-lite,代码行数:21,代码来源:DateAndOrTime.php

示例5: IntlGregorianCalendar

<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
date_default_timezone_set('Europe/Amsterdam');
$intlcal = new IntlGregorianCalendar();
$pstdate = new DateTime('2012-01-01 00:00:00 WEST');
$intlcal->setTimeZone($pstdate->getTimeZone());
var_dump($intlcal->getTimeZone()->getID());
$pstdate = new DateTime('2012-01-01 00:00:00 +24:00');
$intlcal->setTimeZone($pstdate->getTimeZone());
var_dump($intlcal->getTimeZone()->getID());
开发者ID:badlamer,项目名称:hhvm,代码行数:12,代码来源:calendar_setTimeZone_error2.php

示例6: __construct

 /**
  * Creates the iterator
  *
  * You should pass a VCALENDAR component, as well as the UID of the event
  * we're going to traverse.
  *
  * @param Sabre_VObject_Component $comp
  */
 public function __construct(Sabre_VObject_Component $vcal, $uid = null)
 {
     if (is_null($uid)) {
         if ($vcal->name === 'VCALENDAR') {
             throw new InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
         }
         $components = array($vcal);
         $uid = (string) $vcal->uid;
     } else {
         $components = $vcal->select('VEVENT');
     }
     foreach ($components as $component) {
         if ((string) $component->uid == $uid) {
             if (isset($component->{'RECURRENCE-ID'})) {
                 $this->overriddenEvents[$component->DTSTART->getDateTime()->getTimeStamp()] = $component;
                 $this->overriddenDates[] = $component->{'RECURRENCE-ID'}->getDateTime();
             } else {
                 $this->baseEvent = $component;
             }
         }
     }
     if (!$this->baseEvent) {
         throw new InvalidArgumentException('Could not find a base event with uid: ' . $uid);
     }
     $this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
     $this->endDate = null;
     if (isset($this->baseEvent->DTEND)) {
         $this->endDate = clone $this->baseEvent->DTEND->getDateTime();
     } else {
         $this->endDate = clone $this->startDate;
         if (isset($this->baseEvent->DURATION)) {
             $this->endDate->add(Sabre_VObject_DateTimeParser::parse($this->baseEvent->DURATION->value));
         }
     }
     $this->currentDate = clone $this->startDate;
     $rrule = (string) $this->baseEvent->RRULE;
     $parts = explode(';', $rrule);
     foreach ($parts as $part) {
         list($key, $value) = explode('=', $part, 2);
         switch (strtoupper($key)) {
             case 'FREQ':
                 if (!in_array(strtolower($value), array('secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'))) {
                     throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
                 }
                 $this->frequency = strtolower($value);
                 break;
             case 'UNTIL':
                 $this->until = Sabre_VObject_DateTimeParser::parse($value);
                 break;
             case 'COUNT':
                 $this->count = (int) $value;
                 break;
             case 'INTERVAL':
                 $this->interval = (int) $value;
                 break;
             case 'BYSECOND':
                 $this->bySecond = explode(',', $value);
                 break;
             case 'BYMINUTE':
                 $this->byMinute = explode(',', $value);
                 break;
             case 'BYHOUR':
                 $this->byHour = explode(',', $value);
                 break;
             case 'BYDAY':
                 $this->byDay = explode(',', strtoupper($value));
                 break;
             case 'BYMONTHDAY':
                 $this->byMonthDay = explode(',', $value);
                 break;
             case 'BYYEARDAY':
                 $this->byYearDay = explode(',', $value);
                 break;
             case 'BYWEEKNO':
                 $this->byWeekNo = explode(',', $value);
                 break;
             case 'BYMONTH':
                 $this->byMonth = explode(',', $value);
                 break;
             case 'BYSETPOS':
                 $this->bySetPos = explode(',', $value);
                 break;
             case 'WKST':
                 $this->weekStart = strtoupper($value);
                 break;
         }
     }
     // Parsing exception dates
     if (isset($this->baseEvent->EXDATE)) {
         foreach ($this->baseEvent->EXDATE as $exDate) {
             foreach (explode(',', (string) $exDate) as $exceptionDate) {
                 $this->exceptionDates[] = Sabre_VObject_DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
//.........这里部分代码省略.........
开发者ID:RobertWang,项目名称:sabre-zarafa,代码行数:101,代码来源:RecurrenceIterator.php

示例7: memory_get_usage

echo memory_get_usage() . " BYTES<br>" . PHP_EOL;
echo memory_get_peak_usage() . " BYTES<br>" . PHP_EOL;
//var_dump($date_parse($rodrigo));
exit(1);
try {
    $agora = new DateTime();
} catch (Exception $e) {
    echo $e->getMessage();
    exit(1);
}
//$agora->add(new DateInterval("PT10H"));
//var_dump($agora);
///DIE DIE DIE
die;
///DIE DIE DIE
echo "<br />Agora sao " . $agora->format($agora::ATOM) . " in " . $agora->getTimeZone()->getName();
if (isset($_GET['timezone'])) {
    $timezone = $_GET['timezone'];
    $agora->setTimeZone(new DateTimeZone($timezone));
    echo "<br />Agora sao " . $agora->format($agora::RFC822) . " in " . $agora->getTimeZone()->getName();
}
$inTenHours = $agora;
$inTenHours->add(new DateInterval("P1YT10H10M"));
echo "<br>In 1 year it will be " . $inTenHours->format($inTenHours::ATOM);
$timeZones = DateTimeZone::listIdentifiers();
echo "<br><br>";
echo "<form action='index.php' method='GET'>";
echo "<select name='timezone' required>";
echo "<option required>Choose one</option>";
foreach ($timeZones as $timeZone) {
    echo "<option value='{$timeZone}'>{$timeZone}</option>";
开发者ID:kravetz,项目名称:php-tests,代码行数:31,代码来源:index.php

示例8: collect

 /**
  * {@inheritdoc}
  */
 public function collect(MvcEvent $mvcEvent)
 {
     $date = new \DateTime();
     $this->environmentData = array('environment' => getenv('APPLICATION_ENV') ?: 'default', 'timezone' => $date->getTimeZone()->getName(), 'locale' => \Locale::getDefault(), 'php_extensions' => get_loaded_extensions());
 }
开发者ID:juliangut,项目名称:zdt-additions,代码行数:8,代码来源:EnvironmentCollector.php

示例9: stdclass

<?php

ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::fromDateTimeZone());
var_dump(IntlTimeZone::fromDateTimeZone(1, 2));
var_dump(IntlTimeZone::fromDateTimeZone('sdfds'));
var_dump(IntlTimeZone::fromDateTimeZone(new stdclass()));
$dt = new DateTime('2012-08-01 00:00:00 WEST');
var_dump(IntlTimeZone::fromDateTimeZone($dt->getTimeZone()));
var_dump(intltz_from_date_time_zone());
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:timezone_fromDateTimeZone_error.php

示例10: createFromMutable

 /**
  * @note Drop this function when PHP support bumps to 5.6.
  *
  * @param \DateTime $datetime DateTime to convert.
  *
  * @return \DateTimeImmutable
  *
  * @since 2015-08-07
  */
 protected function createFromMutable(\DateTime $datetime)
 {
     $time = $datetime->format('Y-m-d H:i:s');
     $tz = $datetime->getTimeZone();
     $immutable = new \DateTimeImmutable($time, $tz);
     return $immutable;
 }
开发者ID:ofbeaton,项目名称:php-timeago,代码行数:16,代码来源:Timeago.php

示例11: formatted_time

 /**
  * Returns a date/time string with the specified timestamp format
  *
  *     $time = Date::formatted_time('5 minutes ago');
  *
  * @link    http://www.php.net/manual/datetime.construct
  *
  * @param   string $datetime_str     datetime string
  * @param   string $timestamp_format timestamp format
  * @param   string $timezone         timezone identifier
  *
  * @return  string
  */
 public static function formatted_time($datetime_str = 'now', $timestamp_format = null, $timezone = null)
 {
     $timestamp_format = $timestamp_format == null ? Date::$timestamp_format : $timestamp_format;
     $timezone = $timezone === null ? Date::$timezone : $timezone;
     $tz = new DateTimeZone($timezone ? $timezone : date_default_timezone_get());
     $time = new DateTime($datetime_str, $tz);
     if ($time->getTimeZone()->getName() !== $tz->getName()) {
         $time->setTimeZone($tz);
     }
     return $time->format($timestamp_format);
 }
开发者ID:s4urp8n,项目名称:kohana-admin,代码行数:24,代码来源:Date.php

示例12: formatted_time

 /**
  * Returns a date/time string with the specified timestamp format
  *
  * Example:
  * ~~~
  * $time = Date::formatted_time('5 minutes ago');
  * ~~~
  *
  * @link    http://www.php.net/manual/datetime.construct
  *
  * @param   string  $datetime_str      Datetime string [Optional]
  * @param   string  $timestamp_format  Timestamp format [Optional]
  * @param   string  $timezone          Timezone identifier [Optional]
  *
  * @return  string
  *
  * @uses    Config::get
  */
 public static function formatted_time($datetime_str = 'now', $timestamp_format = NULL, $timezone = NULL)
 {
     $settimezone = $timezone === NULL ? self::$timezone : $timezone;
     //Display Dates in site defined timezone format
     if (Config::get('site.timezone_override', FALSE) and $timezone === NULL) {
         // Default timezone from config
         $settimezone = Config::get('site.timezone', 'UTC');
     }
     //convert timestamp to support datetime class
     if (is_numeric($datetime_str)) {
         $datetime_str = '@' . $datetime_str;
     }
     $timestamp_format = $timestamp_format == NULL ? self::$timestamp_format : $timestamp_format;
     $tz = new DateTimeZone($settimezone ? $settimezone : date_default_timezone_get());
     $time = new DateTime($datetime_str, $tz);
     if ($time->getTimeZone()->getName() !== $tz->getName()) {
         $time->setTimeZone($tz);
     }
     return $time->format($timestamp_format);
 }
开发者ID:ultimateprogramer,项目名称:cms,代码行数:38,代码来源:date.php

示例13: DateTimeZone

<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
date_default_timezone_set('Europe/Lisbon');
$tz = IntlTimeZone::fromDateTimeZone(new DateTimeZone('Europe/Amsterdam'));
var_dump($tz->getID(), $tz->getRawOffset());
$dt = new DateTime('2012-01-01 00:00:00 CET');
$dtz = $dt->getTimeZone();
/* this is different from new DateTimeZone('CET'),
 * which gives a Europe/Berlin timezone */
var_dump($dtz->getName());
$tz = IntlTimeZone::fromDateTimeZone($dtz);
var_dump($tz->getID(), $tz->getRawOffset());
$dt = new DateTime('2012-01-01 00:00:00 +0340');
$dtz = $dt->getTimeZone();
/* I don't think this timezone can be generated without a DateTime object */
var_dump($dtz->getName());
$tz = IntlTimeZone::fromDateTimeZone($dtz);
var_dump($tz->getID(), $tz->getRawOffset());
开发者ID:badlamer,项目名称:hhvm,代码行数:20,代码来源:timezone_fromDateTimeZone_basic.php

示例14: IntlGregorianCalendar

<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
date_default_timezone_set('Europe/Amsterdam');
$intlcal = new IntlGregorianCalendar();
$intlcal->setTimeZone('Europe/Paris');
var_dump($intlcal->getTimeZone()->getID());
$intlcal->setTimeZone(new DateTimeZone('Europe/Madrid'));
var_dump($intlcal->getTimeZone()->getID());
$pstdate = new DateTime('2012-01-01 00:00:00 PST');
$intlcal->setTimeZone($pstdate->getTimeZone());
var_dump($intlcal->getTimeZone()->getID());
$offsetdate = new DateTime('2012-01-01 00:00:00 -02:30');
$intlcal->setTimeZone($offsetdate->getTimeZone());
var_dump($intlcal->getTimeZone()->getID());
开发者ID:badlamer,项目名称:hhvm,代码行数:16,代码来源:calendar_setTimeZone_variation2.php

示例15: array

<?php

$test_dates = array('2008-01-01 12:00:00 PDT', '2008-01-01 12:00:00 +02:00');
foreach ($test_dates as $test_date) {
    $d1 = new DateTime($test_date);
    $d2 = new DateTime('2008-01-01 12:00:00 UTC');
    echo $d1->format(DATE_ISO8601), PHP_EOL;
    echo $d2->format(DATE_ISO8601), PHP_EOL;
    $tz = $d1->getTimeZone();
    $d2->setTimeZone($tz);
    echo $d1->format(DATE_ISO8601), PHP_EOL;
    echo $d2->format(DATE_ISO8601), PHP_EOL;
    echo PHP_EOL;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:14,代码来源:bug45543.php


注:本文中的DateTime::getTimeZone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。