本文整理匯總了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;
}