如题,task和api写入的时区不一致.api打印出来的日志时区是utc的,task打印出来是cst的.
["context"]=>
array(0) {
}
["level"]=>
int(200)
["level_name"]=>
string(4) "INFO"
["channel"]=>
string(7) "default"
["datetime"]=>
object(Monolog\DateTimeImmutable)#10153 (4) {
["useMicroseconds":"Monolog\DateTimeImmutable":private]=>
bool(true)
["date"]=>
string(26) "2025-08-22 09:58:34.249670"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["extra"]=>
array(0) {
}
["message"]=>
string(57) "end_app\crontab\tasks\ChargeOrderExpiredCloseTask::handle"
["context"]=>
array(0) {
}
["level"]=>
int(100)
["level_name"]=>
string(5) "DEBUG"
["channel"]=>
string(7) "crontab"
["datetime"]=>
object(Monolog\DateTimeImmutable)#10889 (4) {
["useMicroseconds":"Monolog\DateTimeImmutable":private]=>
bool(true)
["date"]=>
string(26) "2025-08-22 17:58:01.366563"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Asia/Shanghai"
}
["extra"]=>
array(0) {
}
["formatted"]=>
string(101) "[2025-08-22 17:58:01] crontab.DEBUG: end_app\crontab\tasks\ChargeOrderExpiredCloseTask::handle [] []
app.php
'debug' => !(env("APP_ENV") == "ONLINE"),
'error_reporting' => E_ALL,
'default_timezone' => 'Asia/Shanghai',
'request_class' => Request::class,
'public_path' => base_path() . DIRECTORY_SEPARATOR . 'public',
'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime',
'controller_suffix' => 'Controller',
'controller_reuse' => false,
无法完全复现,我在别的项目里,api时间又是正常的,很奇怪. 尝试在bootstrap.php里设置默认时区,是正常的.但是不知道问题在哪.其他项目没出现异常
把服务器的时间也改为中国时间就可以了