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


PHP DateTime::setTimezone方法代码示例

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


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

示例1: validateAttribute

 /**
  * @inheritdoc
  */
 public function validateAttribute($model, $attribute)
 {
     $timestamp = $this->parseDateTimeValue($model->{$attribute}, $this->getTimeValue($model));
     if ($timestamp === false) {
         $this->addError($model, $attribute, $this->message, []);
     } elseif ($this->min !== null && $timestamp < $this->min) {
         $this->addError($model, $attribute, $this->tooSmall, ['min' => $this->minString]);
     } elseif ($this->max !== null && $timestamp > $this->max) {
         $this->addError($model, $attribute, $this->tooBig, ['max' => $this->maxString]);
     } elseif (!$this->isInDbFormat($model->{$attribute})) {
         // If there is no error, and attribute is not yet in DB Format - convert to DB
         $date = new \DateTime();
         $date->setTimestamp($timestamp);
         if ($this->hasTime()) {
             // Convert timestamp to apps timeZone
             $date->setTimezone(new \DateTimeZone(\Yii::$app->timeZone));
         } else {
             // If we do not need to respect time, set timezone to utc
             // To ensure we're saving 00:00:00 time infos.
             $date->setTimezone(new \DateTimeZone('UTC'));
         }
         if ($this->convertToFormat !== null) {
             $model->{$attribute} = $date->format($this->convertToFormat);
         }
     }
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:29,代码来源:DbDateValidator.php

示例2: onMessage

 /**
  * When a message arrives that contains a trigger, this is started
  *
  * @param $msgData
  */
 public function onMessage($msgData)
 {
     $message = $msgData->message->message;
     $data = $this->trigger->trigger($message, $this->information()["trigger"]);
     if (isset($data["trigger"])) {
         $channelName = $msgData->channel->name;
         $guildName = $msgData->guild->name;
         $date = date("d-m-Y");
         $fullDate = date("Y-m-d H:i:s");
         $dateTime = new DateTime($fullDate);
         $et = $dateTime->setTimezone(new DateTimeZone("America/New_York"));
         $et = $et->format("H:i:s");
         $pt = $dateTime->setTimezone(new DateTimeZone("America/Los_Angeles"));
         $pt = $pt->format("H:i:s");
         $utc = $dateTime->setTimezone(new DateTimeZone("UTC"));
         $utc = $utc->format("H:i:s");
         $cet = $dateTime->setTimezone(new DateTimeZone("Europe/Copenhagen"));
         $cet = $cet->format("H:i:s");
         $msk = $dateTime->setTimezone(new DateTimeZone("Europe/Moscow"));
         $msk = $msk->format("H:i:s");
         $aest = $dateTime->setTimezone(new DateTimeZone("Australia/Sydney"));
         $aest = $aest->format("H:i:s");
         $msg = "**Current EVE Time:** {$utc} / **EVE Date:** {$date} / **PT:** {$pt} / **ET:** {$et} / **CET:** {$cet} / **MSK:** {$msk} / **AEST:** {$aest}";
         $this->log->info("Sending time info to {$channelName} on {$guildName}");
         $msgData->user->reply($msg);
     }
 }
开发者ID:karbowiak,项目名称:Sluggard,代码行数:32,代码来源:eveTime.php

示例3: __construct

 /**
  * Constructor.
  *
  * @param \Ecn\RiftConnector\Entity\Zone $zone
  * @param string                         $name
  * @param string                         $startDate Unix Timestamp
  */
 public function __construct(Zone $zone, $name, $startDate)
 {
     $this->name = $name;
     $this->startDate = new \DateTime('@' . $startDate);
     $this->startDate->setTimezone(new \DateTimeZone(date('e')));
     $this->zone = $zone;
 }
开发者ID:elbcoast,项目名称:ECNRiftConnector,代码行数:14,代码来源:Event.php

示例4: setUp

 /**
  * @return void
  */
 public function setUp()
 {
     $this->sampleLocale = new \TYPO3\Flow\I18n\Locale('en');
     $this->sampleLocalizedLiterals = (require __DIR__ . '/../Fixtures/MockLocalizedLiteralsArray.php');
     $this->sampleDateTime = new \DateTime('@1276192176');
     $this->sampleDateTime->setTimezone(new \DateTimeZone('Europe/London'));
 }
开发者ID:cerlestes,项目名称:flow-development-collection,代码行数:10,代码来源:DatetimeFormatterTest.php

示例5: set

 /**
  * Sets the properties in this object as received from the webhook
  *
  * @return void
  */
 public function set($properties)
 {
     $this->properties = $properties;
     if (isset($properties['event'])) {
         $this->event = $properties['event'];
     }
     if (isset($properties['email'])) {
         $this->email = $properties['email'];
     }
     if (isset($properties['timestamp'])) {
         if (is_numeric($properties['timestamp'])) {
             $this->timestamp = new DateTime('@' . $properties['timestamp']);
         } elseif (is_array($properties['timestamp'])) {
             $this->timestamp = new DateTime($properties['timestamp']['date'], new DateTimezone($properties['timestamp']['timezone']));
         }
     } else {
         $this->timestamp = new DateTime('now');
     }
     $this->timestamp->setTimezone(new DateTimezone('UTC'));
     if (isset($properties['category'])) {
         $this->category = $properties['category'];
     }
     if (!empty($properties['data'])) {
         $this->data = $properties['data'];
     }
 }
开发者ID:lorenzo,项目名称:cakephp-gridhook,代码行数:31,代码来源:SendgridEvent.php

示例6: getDateStringFromDateTime

 /**
  * @param \DateTime $dateTime
  * @return string
  */
 public function getDateStringFromDateTime(\DateTime $dateTime)
 {
     $savedTimeZone = $dateTime->getTimezone();
     $dateTime->setTimezone(new \DateTimeZone($this->targetSystemTimeZone));
     $restApiDateString = $dateTime->format($this->targetSystemDateFormat);
     $dateTime->setTimezone($savedTimeZone);
     return $restApiDateString;
 }
开发者ID:aoemedia,项目名称:searchperience-api-client,代码行数:12,代码来源:DateTimeService.php

示例7: __construct

 /**
  * @param \DateTime $begin should be in UTC date time zone, if not - it will be cast to UTC
  * @param \DateTime $end should be in UTC date time zone, if not - it will be cast to UTC
  */
 public function __construct(\DateTime $begin, \DateTime $end)
 {
     if ($begin > $end) {
         throw new \InvalidArgumentException('Begin date can not be greater than end date.');
     }
     $timezone = new \DateTimeZone(self::DEFAULT_TIMEZONE);
     $this->begin = clone $begin;
     $this->end = clone $end;
     $this->begin->setTimezone($timezone);
     $this->end->setTimezone($timezone);
 }
开发者ID:vdrizheruk,项目名称:OroCrmTimeLapBundle,代码行数:15,代码来源:Period.php

示例8: testSetTimezone

 /**
  *
  */
 public function testSetTimezone()
 {
     $dt = new DateTime('2013-03-08 10:00:00');
     $dt->setTimezone('Europe/Berlin');
     $this->assertEquals('2013-03-08 11:00:00', $dt->format('Y-m-d H:i:s'));
     $this->assertEquals('Europe/Berlin', $dt->getTimezone()->getName());
     $dt->setTimezone(new \DateTimeZone('Indian/Mahe'), true);
     $this->assertEquals('2013-03-08 11:00:00', $dt->format('Y-m-d H:i:s'));
     $this->assertEquals('Indian/Mahe', $dt->getTimezone()->getName());
     $dt->setTimezone(null);
     $this->assertEquals('UTC', $dt->getTimezone()->getName());
 }
开发者ID:phellow,项目名称:date,代码行数:15,代码来源:DateTimeTest.php

示例9: toString

 public function toString(\DateTime $pDateTime, $pDateTimeZone)
 {
     if ($pDateTimeZone->getName() == $pDateTime->getTimezone()->getName()) {
         return $pDateTime->format('c');
     } else {
         $lDateTimeZone = $pDateTime->getTimezone();
         $pDateTime->setTimezone($pDateTimeZone);
         $lDateTimeString = $pDateTime->format('c');
         $pDateTime->setTimezone($lDateTimeZone);
         return $lDateTimeString;
     }
     return $pDateTime->format('c');
 }
开发者ID:jeanphilippe-p,项目名称:ObjectManagerLib,代码行数:13,代码来源:DateTime.php

示例10: testValidSendbankPayment

 public function testValidSendbankPayment()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $templating->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'callbackValidsendbank')));
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $order = new OgonePaymentTest_Order();
     $order->setCreatedAt($date);
     $order->setId(2);
     $order->setReference('FR');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->setCurrency($currency);
     $order->setCustomer($customer);
     $order->setLocale('es');
     $payment = new OgonePayment($router, $logger, $templating, true);
     $payment->setCode('ogone_1');
     $payment->setOptions(array('url_return_ok' => '', 'url_return_ko' => '', 'url_callback' => '', 'template' => '', 'form_url' => '', 'sha_key' => '', 'sha-out_key' => '', 'pspid' => '', 'home_url' => '', 'catalog_url' => ''));
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
开发者ID:sonata-project,项目名称:ecommerce,代码行数:25,代码来源:OgonePaymentTest.php

示例11: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $tz = $this->getContainer()->getParameter('default_timezone');
         $plus = $this->getContainer()->getParameter('gmt_as_number');
         $date = new \DateTime("now");
         $date->setTimezone(new \DateTimeZone($tz))->modify('+' . $plus . ' hour');
         $output->writeln(sprintf('<info>[%s]</info> Parsing time is (<info>%s</info>) Egypt local time ...', date('G:i:s'), $date->format('l, F jS h:i:s')));
         $powerGridService = $this->getContainer()->get('power_grid_service');
         $status = $powerGridService->getStatus();
         if ($status) {
             $em = $this->getContainer()->get('doctrine')->getManager();
             $record = new Status();
             $record->setStatus($status);
             $record->setTimestamp($date);
             $em->persist($record);
             $em->flush();
             $output->writeln(sprintf('<info>[%s]</info> NEW STATUS (<info>%s</info>) ...', date('G:i:s'), $status));
         } else {
             $output->writeln(sprintf('<info>[%s]</info> UNKNOWN STATUS, TRY AGAIN ...', date('G:i:s')));
         }
     } catch (\Exception $e) {
         $this->getContainer()->get('doctrine')->resetManager();
         $output->writeln(sprintf('<info>[%s]</info> <error>[error]</error> %s', date('G:i:s'), $e->getMessage()));
     }
 }
开发者ID:ahmedgroup1,项目名称:gridstatusnow,代码行数:26,代码来源:SaveStatusNowCommand.php

示例12: setTimezone

 /**
  * Sets the date and time based on an Unix timestamp.
  *
  * @param DateTimeZone $timezone A DateTimeZone object representing the desired time zone.
  * @return KDate or FALSE on failure.
  */
 public function setTimezone(DateTimeZone $timezone)
 {
     if ($this->_date->setTimezone($timezone) === false) {
         return false;
     }
     return $this;
 }
开发者ID:daodaoliang,项目名称:nooku-framework,代码行数:13,代码来源:date.php

示例13: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //$datetime = Carbon::now('Asia/Bangkok');
     $date = new DateTime();
     $date->setTimezone(new DateTimeZone('Asia/Bangkok'));
     DB::table('users')->insert(['name' => 'Pathma In', 'firstName' => 'Pathma', 'lastName' => 'Inpromma', 'cardID' => '1490300066761', 'phone' => '0909359085', 'code' => $date->format('YmdHis'), 'email' => 'mychappa@gmail.com', 'password' => bcrypt('kantavee'), 'created_at' => $date->format('Y-m-d H:i:s'), 'role' => 99]);
 }
开发者ID:snookerjirayut,项目名称:jj-laravel5,代码行数:12,代码来源:UserTableSeeder.php

示例14: convertPHPFormatDateToISOFormatDate

 public function convertPHPFormatDateToISOFormatDate($inputPHPFormat, $date)
 {
     $dateFormat = new sfDateFormat();
     try {
         $symfonyPattern = $this->__getSymfonyDateFormatPattern($inputPHPFormat);
         $dateParts = $dateFormat->getDate($date, $symfonyPattern);
         if (is_array($dateParts) && isset($dateParts['year']) && isset($dateParts['mon']) && isset($dateParts['mday'])) {
             $day = $dateParts['mday'];
             $month = $dateParts['mon'];
             $year = $dateParts['year'];
             // Additional check done for 3 digit years, or more than 4 digit years
             if (checkdate($month, $day, $year) && $year >= 1000 && $year <= 9999) {
                 $dateTime = new DateTime();
                 $dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
                 $dateTime->setDate($year, $month, $day);
                 $date = $dateTime->format('Y-m-d');
                 return $date;
             } else {
                 return "Invalid date";
             }
         }
     } catch (Exception $e) {
         return "Invalid date";
     }
     return null;
 }
开发者ID:lahirwisada,项目名称:orangehrm,代码行数:26,代码来源:LocalizationService.php

示例15: getLocalDateTime

	/** 
	 * Gets the date time for the local time zone/area if user timezones are enabled, if not returns system datetime
	 * @param string $systemDateTime
	 * @param string $format
	 * @return string $datetime
	 */
	public function getLocalDateTime($systemDateTime = 'now', $mask = NULL) {
		if(!isset($mask) || !strlen($mask)) {
			$mask = 'Y-m-d H:i:s';
		}
		
		$req = Request::get();
		if ($req->hasCustomRequestUser()) {
			return date($mask, strtotime($req->getCustomRequestDateTime()));
		}
		
		if(!isset($systemDateTime) || !strlen($systemDateTime)) {
			return NULL; // if passed a null value, pass it back
		} elseif(strlen($systemDateTime)) {
			$datetime = new DateTime($systemDateTime);
		} else {
			$datetime = new DateTime();
		}
		
		if(defined('ENABLE_USER_TIMEZONES') && ENABLE_USER_TIMEZONES) {
			$u = new User();
			if($u && $u->isRegistered()) {
				$utz = $u->getUserTimezone();
				if($utz) {
					$tz = new DateTimeZone($utz);
					$datetime->setTimezone($tz);
				}
			}
		}
		if (Localization::activeLocale() != 'en_US') {
			return $this->dateTimeFormatLocal($datetime,$mask);
		} else {
			return $datetime->format($mask);
		}
	}
开发者ID:nveid,项目名称:concrete5,代码行数:40,代码来源:date.php


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