本文整理汇总了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;
}