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


PHP float::getTimestamp方法代码示例

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


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

示例1: __construct

 /**
  * @param \DateTime|string|float $input    The date or a string the DateTime c'tor can understand or a timestamp
  * @param \DateTimeZone|string   $timezone The timezone or a string the DateTimeZone c'tor can understand
  */
 public function __construct($input, $timezone)
 {
     if (!$timezone instanceof \DateTimeZone) {
         $timezone = new \DateTimeZone((string) $timezone);
     }
     /////
     // We have to trick PHP a bit here, but why?
     //
     // Apparently things behave different, when setting a timezone like
     // a) 'Europe/Berlin'
     // b) '+02:00'
     //
     // When the date already has a timezone set then
     // a) will only set the timezone
     // b) will set the timezone and will also change the timestamp by 2 hours
     //
     // Therefore we create a fresh date, that does not have a timezone yet, set the timestamp, and then apply the
     // timezone
     //
     // See the unit tests for more as well
     ////
     if ($input instanceof \DateTime) {
         $date = (new \DateTime())->setTimestamp($input->getTimestamp())->setTimezone($timezone);
     } elseif (is_numeric($input)) {
         $date = (new \DateTime())->setTimestamp($input)->setTimezone($timezone);
     } else {
         // when we have string input, we immediately use the timezone
         $tmp = new \DateTime($input, $timezone);
         // we reconstruct the date time again in order to set the timezone on the inner one
         $date = (new \DateTime())->setTimestamp($tmp->getTimestamp())->setTimezone($timezone);
     }
     $this->date = $date;
     $this->timezone = $timezone;
 }
开发者ID:peekandpoke,项目名称:psi,代码行数:38,代码来源:LocalDate.php


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