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


PHP DateTime::setTimeZone方法代码示例

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


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

示例1: getCreated

 function getCreated()
 {
     if (!$this->localized) {
         $this->created->setTimeZone(new \DateTimeZone($this->timezone));
     }
     return $this->created;
 }
开发者ID:beimar2,项目名称:doctrine2-example,代码行数:7,代码来源:Event.php

示例2: rateThisBook

 public function rateThisBook()
 {
     $currentUserId = Auth::id();
     $bookIdToRate = $_POST['bookIdToRate'];
     $ratingInput = "";
     if (isset($_POST['userRating'])) {
         $ratingInput = $_POST['userRating'];
     }
     $datetime = new \DateTime();
     $datetime->setTimeZone(new \DateTimeZone('Europe/Skopje'));
     $rated = DB::select('select * from bookstore.ratings where book_id = ' . $bookIdToRate . ' and user_id =' . $currentUserId);
     //        print_r($rated);
     if (sizeof($rated) == 0) {
         if ($ratingInput >= 6 && $ratingInput <= 10) {
             $idTag = DB::table('ratings')->insertGetId(array('book_id' => $bookIdToRate, 'user_id' => $currentUserId, 'rating' => $ratingInput, 'created_at' => $datetime, 'updated_at' => $datetime));
         }
     } else {
         if ($ratingInput >= 6 && $ratingInput <= 10) {
             DB::table('ratings')->where('book_id', $bookIdToRate)->where('user_id', $currentUserId)->update(array('rating' => $ratingInput, 'updated_at' => $datetime));
         }
     }
     $path = '/book/' . $bookIdToRate;
     header("Location: " . $path);
     exit;
 }
开发者ID:EmilijaD,项目名称:bookStore,代码行数:25,代码来源:RateBookController.php

示例3: reverseTransform

    /**
     * Transforms a date string in the configured timezone into a DateTime object
     *
     * @param  string $value  A value as produced by PHP's date() function
     * @return DateTime       A DateTime object
     */
    public function reverseTransform($value)
    {
        if (empty($value)) {
            return null;
        }

        if (!is_string($value)) {
            throw new UnexpectedTypeException($value, 'string');
        }

        $outputTimezone = $this->outputTimezone;
        $inputTimezone = $this->inputTimezone;

        try {
            $dateTime = new \DateTime("$value $outputTimezone");

            if ($inputTimezone != $outputTimezone) {
                $dateTime->setTimeZone(new \DateTimeZone($inputTimezone));
            }

            return $dateTime;
        } catch (\Exception $e) {
            throw new \InvalidArgumentException('Expected a valid date string. ' . $e->getMessage(), 0, $e);
        }
    }
开发者ID:nacef,项目名称:symfony,代码行数:31,代码来源:DateTimeToStringTransformer.php

示例4: retrieveEdtCreneauActuel

	/**
	 *
	 * Renvoi le creneau actuel
	 *
	 * @return     EdtCreneau EdtCreneau
	 *
	 */
	public static function retrieveEdtCreneauActuel($v = 'now') {
		// we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
		// -- which is unexpected, to say the least.
		//$dt = new DateTime();
		if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = clone $v;
		} else {
			// some string/numeric value passed; we normalize that so that we can
			// validate it.
			try {
				if (is_numeric($v)) { // if it's a unix timestamp
					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
					// We have to explicitly specify and then change the time zone because of a
					// DateTime bug: http://bugs.php.net/bug.php?id=43003
					$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		return EdtCreneauQuery::create()->filterByHeuredebutDefiniePeriode($dt->format("H:i:s"), Criteria::LESS_EQUAL)
		    ->filterByHeurefinDefiniePeriode($dt->format("H:i:s"), Criteria::GREATER_THAN)->findOne();
	}
开发者ID:rhertzog,项目名称:lcs,代码行数:35,代码来源:EdtCreneauPeer.php

示例5: getTime

/**
 * get a formatted date and time from a unix timestamp and time zone
 *
 * @param string $unixTime - a unix timestamp
 * @param string $timeZone - a timezone for this timestamp
 *
 * @return string $date - a formatted date and time with associated time zone
 */
function getTime($unixTime, $timeZone)
{
    $date = new DateTime();
    $date->setTimestamp($unixTime);
    $date->setTimeZone(new DateTimeZone($timeZone));
    return $date->format("h:i:s a T D M j Y");
}
开发者ID:jwnannas,项目名称:weatherdrive,代码行数:15,代码来源:weather.php

示例6: convert

function convert($timestamp)
{
    $schedule_date = new DateTime($timestamp, new DateTimeZone(date_default_timezone_get()));
    $schedule_date->setTimeZone(new DateTimeZone('UTC'));
    $triggerOn = $schedule_date->format('Y-m-d H:i:s');
    echo $triggerOn;
}
开发者ID:blazy2k9,项目名称:nisam-election,代码行数:7,代码来源:result.php

示例7: phabricator_format_local_time

/**
 * This function does not usually need to be called directly. Instead, call
 * @{function:phabricator_date}, @{function:phabricator_time}, or
 * @{function:phabricator_datetime}.
 *
 * @param int Unix epoch timestamp.
 * @param PhabricatorUser User viewing the timestamp.
 * @param string Date format, as per DateTime class.
 * @return string Formatted, local date/time.
 */
function phabricator_format_local_time($epoch, $user, $format)
{
    if (!$epoch) {
        // If we're missing date information for something, the DateTime class will
        // throw an exception when we try to construct an object. Since this is a
        // display function, just return an empty string.
        return '';
    }
    $user_zone = $user->getTimezoneIdentifier();
    static $zones = array();
    if (empty($zones[$user_zone])) {
        $zones[$user_zone] = new DateTimeZone($user_zone);
    }
    $zone = $zones[$user_zone];
    // NOTE: Although DateTime takes a second DateTimeZone parameter to its
    // constructor, it ignores it if the date string includes timezone
    // information. Further, it treats epoch timestamps ("@946684800") as having
    // a UTC timezone. Set the timezone explicitly after constructing the object.
    try {
        $date = new DateTime('@' . $epoch);
    } catch (Exception $ex) {
        // NOTE: DateTime throws an empty exception if the format is invalid,
        // just replace it with a useful one.
        throw new Exception(pht("Construction of a DateTime() with epoch '%s' " . "raised an exception.", $epoch));
    }
    $date->setTimeZone($zone);
    return PhutilTranslator::getInstance()->translateDate($format, $date);
}
开发者ID:denghp,项目名称:phabricator,代码行数:38,代码来源:viewutils.php

示例8: convert_time

 public static function convert_time($time, $local_timezone, $target_timezone)
 {
     date_default_timezone_set($local_timezone);
     $datetime = new DateTime($time);
     $timezone = new DateTimeZone($target_timezone);
     return $datetime->setTimeZone($timezone)->format('Y-m-d H:i');
 }
开发者ID:kudoshinichivn,项目名称:lazypost,代码行数:7,代码来源:LazySalesHelper.php

示例9: setTimeStamp

 /**
  * Sets the value of [timestamp] column to a normalized version of the date/time value specified.
  * 
  * @param      mixed $v string, integer (timestamp), or DateTime value.  Empty string will
  *						be treated as NULL for temporal objects.
  */
 public function setTimeStamp($v)
 {
     // we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
     // -- which is unexpected, to say the least.
     if ($v === null || $v === '') {
         $dt = null;
     } elseif ($v instanceof DateTime) {
         $dt = $v;
     } else {
         // some string/numeric value passed; we normalize that so that we can
         // validate it.
         try {
             if (is_numeric($v)) {
                 // if it's a unix timestamp
                 $dt = new DateTime('@' . $v, new DateTimeZone('UTC'));
                 // We have to explicitly specify and then change the time zone because of a
                 // DateTime bug: http://bugs.php.net/bug.php?id=43003
                 $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
             } else {
                 $dt = new DateTime($v);
             }
         } catch (Exception $x) {
             throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
         }
     }
     if ($this->timeStamp !== null || $dt !== null) {
         // (nested ifs are a little easier to read in this case)
         $currNorm = $this->timeStamp !== null && ($tmpDt = new DateTime($this->timeStamp)) ? $tmpDt->format('Y-m-d H:i:s') : null;
         $newNorm = $dt !== null ? $dt->format('Y-m-d H:i:s') : null;
         if ($currNorm !== $newNorm) {
             $this->timeStamp = $dt ? $dt->format('Y-m-d H:i:s') : null;
         }
     }
     // if either are not null
 }
开发者ID:DBezemer,项目名称:server,代码行数:41,代码来源:kBatchHistoryData.php

示例10: phabricator_datetime

function phabricator_datetime($epoch, $user)
{
    $zone = new DateTimeZone($user->getTimezoneIdentifier());
    $date = new DateTime('@' . $epoch);
    $date->setTimeZone($zone);
    return $date->format('M j Y, g:i A');
}
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:7,代码来源:viewutils.php

示例11: getCodeByDateReuse

 public function getCodeByDateReuse($subcode = null)
 {
     $stmt = $this->getPdo()->prepare("\n\t\t\t\tSELECT DATE_FORMAT(CURRENT_TIMESTAMP, '%Y-%m-%dT%TZ')\n\t\t\t");
     $stmt->execute();
     $date = new \DateTime($stmt->fetchColumn());
     $date->setTimeZone(new \DateTimeZone($this->config['timezone']));
     return $this->getCode($subcode, $date->format('Ymd'));
 }
开发者ID:mrpachara,项目名称:php-lib,代码行数:8,代码来源:GeneratorService.php

示例12: testTransform_differentTimezones

 public function testTransform_differentTimezones()
 {
     $transformer = new StringToDateTimeTransformer(array('input_timezone' => 'America/New_York', 'output_timezone' => 'Asia/Hong_Kong'));
     $output = new \DateTime('2010-02-03 04:05:06 America/New_York');
     $input = $output->format('Y-m-d H:i:s');
     $output->setTimeZone(new \DateTimeZone('Asia/Hong_Kong'));
     $this->assertDateTimeEquals($output, $transformer->transform($input));
 }
开发者ID:jarosz,项目名称:symfony,代码行数:8,代码来源:StringToDateTimeTransformerTest.php

示例13: tzFormatDate

 /**
  *
  * @param <type> $gmdate
  * @param <type> $format
  * @param <type> $timezone
  * @return <type>
  */
 public static function tzFormatDate($gmdate, $format = false, $timezone = false)
 {
     $format = $format ?: DATE_FORMAT;
     $timezone = $timezone ?: 'UTC';
     $cnv_date = new DateTime($gmdate);
     $cnv_date->setTimeZone(new DateTimeZone($timezone));
     return $cnv_date->format($format);
 }
开发者ID:viveleroi,项目名称:AspenMSM,代码行数:15,代码来源:Date.php

示例14: testSetDateTimeInvalid

 /**
  * @expectedException InvalidArgumentException
  */
 function testSetDateTimeInvalid()
 {
     $tz = new \DateTimeZone('Europe/Amsterdam');
     $dt = new \DateTime('1985-07-04 01:30:00', $tz);
     $dt->setTimeZone($tz);
     $elem = new MultiDateTime('DTSTART');
     $elem->setDateTimes(array($dt), 7);
 }
开发者ID:floffel03,项目名称:pydio-core,代码行数:11,代码来源:MultiDateTimeTest.php

示例15: getNTPTime

 public function getNTPTime()
 {
     // go and get the time from some NTP server (for now, we doing the same as the default, as an example)
     $timezone = new \DateTimeZone($this->timezone);
     $date = new \DateTime();
     $date->setTimeZone($timezone);
     return $date;
 }
开发者ID:ahundiak,项目名称:webMVc,代码行数:8,代码来源:Clock.php


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