本文整理汇总了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;
}
示例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);
}
示例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."));
}
}
}
示例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;
}
示例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());
示例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());
//.........这里部分代码省略.........
示例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>";
示例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());
}
示例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());
示例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;
}
示例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);
}
示例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);
}
示例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());
示例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());
示例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;
}