Carbon:return 基于输入日期字符串和时区的时间戳
Carbon: return a timestamp based on input date string AND timezone
以 Europe/Paris (+02:00) 的某个人为例。
我想构建一个函数,在其中传入日期和时间字符串 ('2016-10-6 06:00 PM') 和我的时区标识符 ('Europe/Paris')。我想要 return 相应的 GMT 时间戳。
getTimestamp('2016-10-6 06:00 PM', 'Europe/Paris')
这是我目前的情况:
public function getTimestamp($string, $time_zone)
{
$c = Carbon::parse($string);
$c->timezone = new DateTimeZone($time_zone);
return $c->timestamp;
}
问题
如果传递 2016-10-06 06:00 PM
的日期和时间以及 Europe/Paris
的时区,我会返回对应于 2016-10-06 06:00 PM GMT 的 UTC 时间戳。
应该是 return格林威治标准时间 04:00 因为 Europe/Paris 提前两个小时。
问题
如何传递日期和时区并返回具有正确偏移量的 GMT 时间戳。
解析函数允许你传入时区
public static function parse($time = null, $tz = null)
所以把它传进来:
$c = Carbon::parse($string, $time_zone);
以 Europe/Paris (+02:00) 的某个人为例。
我想构建一个函数,在其中传入日期和时间字符串 ('2016-10-6 06:00 PM') 和我的时区标识符 ('Europe/Paris')。我想要 return 相应的 GMT 时间戳。
getTimestamp('2016-10-6 06:00 PM', 'Europe/Paris')
这是我目前的情况:
public function getTimestamp($string, $time_zone)
{
$c = Carbon::parse($string);
$c->timezone = new DateTimeZone($time_zone);
return $c->timestamp;
}
问题
如果传递 2016-10-06 06:00 PM
的日期和时间以及 Europe/Paris
的时区,我会返回对应于 2016-10-06 06:00 PM GMT 的 UTC 时间戳。
应该是 return格林威治标准时间 04:00 因为 Europe/Paris 提前两个小时。
问题
如何传递日期和时区并返回具有正确偏移量的 GMT 时间戳。
解析函数允许你传入时区
public static function parse($time = null, $tz = null)
所以把它传进来:
$c = Carbon::parse($string, $time_zone);