讨论数量:
我看了下 Carbon 的文档,这应该是 Carbon 3 的行为,之前的 Carbon 2 应该是会继承的。
You can create instances from unix timestamps. createFromTimestamp() create a Carbon instance equal to the given timestamp and will set the timezone to the given timezone as second parameter, or to UTC if non given (since Carbon 3) (in previous versions it defaulted to date_default_timezone_get()).
而 Laravel 应该是用 date_default_timezone_get
设置了默认时区。
去年踩过这个坑, laravel的这个Facade有点问题, 保险起见我直接手动 Carbon::createFromTimestamp($time, Config::get('app.timezone'))
boot 一下这段代码
\Illuminate\Support\DateFactory::useCallable(
static fn (mixed $result): mixed => $result instanceof \DateTime || $result instanceof \DateTimeImmutable
? $result->setTimezone(config('app.timezone'))
: $result
);
推荐文章: