我正在尝试使用Carbon在Laravel 5.3中从UTC偏移获取时区名称。以下是代码,任何帮助都将不胜感激。
我错过了什么吗?我感觉很愚蠢。。
/* current code iteration */
$utcOffset = -5;
$timezone = Carbon::now($utcOffset)->timezone->getName();
echo $timezone;
// Result: -05:00
// Expected Result: EST
/* tried code */
$timezone = Carbon::now($utcOffset)->tzName;
// Result: -05:00
/* What I used prior to Carbon */
$timezone = timezone_name_from_abbr(null, $utcOffset * 3600, TRUE);
$dateTime = new DateTime();
$dateTime->setTimeZone(new DateTimeZone($timezone));
$timezone = $dateTime->format('T');'
我错过了什么吗?我感觉很愚蠢。。
$now->tzName
。 - Vitalii Strimbanu->tzName
应该是可以工作的,而且根据我的测试,它也确实可以工作。那么问题肯定出在其他地方。如果有帮助的话,我是在 Laravel 5.3 项目和 Carbon 版本 1.22.1 上进行测试的。 - DevK