繁体   English   中英

管理时区 JS 两个小时的差异

[英]manage timezones JS difference of two hours

前端我在这个日期发送 axios:

Mon Jun 13 2022 18:29:00 GMT+0200 (Ora legale dell’Europa centrale)

因为后端(laravel 8.x)端为我节省了通常的一个,如下所示:

2022-06-13 16:29:00

我希望他能在 18:29 而不是 16:29 救我

我该如何处理? 我无法安装像 moment.js 这样的库

这可能是由于您的应用时区设置为 UTC。 我个人建议将所有内容存储在 UTC 中,并将其转换为前端显示的目的。

但是,如果您必须以相同的格式存储它们,则需要在config/app.php设置时区

/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/

'timezone' => 'UTC', <--- Change this to your timezone eg: Africa/Cairo

从此列表中选择正确的时区。

GMT+0200 可用的时区

不要忘记运行php artisan config:clear以确保正在使用您的时区配置更改。

我解决如下:

    return new Date(year, month - 1, day, hours, minutes, seconds).toString().slice(0, 24);

你能做得更好吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM