gpt4 book ai didi

laravel - 如何为时间戳设置Laravel Carbon时区?

转载 作者:行者123 更新时间:2023-12-04 02:34:30 25 4
gpt4 key购买 nike

我有一个主要基于CET地区的项目。我在config / app.php中设置了CET,
但基地中的所有枢轴时间戳都存储在UTC时间中?

如何设置时间戳的“全局”时区?

我做了这个测试:

<?php
$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;
echo "<br />".date('m/d/Y h:i:s a', time());

$mytime = Carbon\Carbon::now();
echo "<br />".$mytime->toDateTimeString();
?>


结果如下:

The current server timezone is: CET
06/09/2016 12:06:04 pm
2016-06-09 11:06:04


n
ÿ

最佳答案

Carbon使用默认的DateTime PHP对象,因此请使用date_default_timezone_set()函数,例如:
date_default_timezone_set('Europe/London');

关于laravel - 如何为时间戳设置Laravel Carbon时区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37722681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com