Laravel系统的乡村时间

发布于 2025-01-24 15:39:05 字数 55 浏览 1 评论 0原文

我在一个网站在一个国家开放时需要我想要的课程系统,该课程的时间是用户在用户所在的国家的实时出现的

I work on a course system that has course times I want when the site is opened in a country, the time of the course appears for the user in the real time of the country in which the user is located

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2025-01-31 15:39:05

将用户时间转换为UTC使用,在您的控制器方法中使用Laravel代码后使用UTC的

# convert user date provided date string to user date
$user_date = date('Y-m-d H:i:s', strtotime($date_string));

# convert user date to utc date
$utc_date = Carbon::createFromFormat('Y-m-d H:i', $user_date, $user->timezone);
$utc_date->setTimezone('UTC');

# check the utc date
dd($utc_date);

时间将UTC时间转换为用户时间

# using utc date convert date to user date
$user_date = Carbon::createFromFormat('Y-m-d H:i', $utc_date, 'UTC');
$user_date->setTimezone($user->timezone);

# check the user date
dd($user_date);

To convert user time to UTC use following laravel code in your controller method

# convert user date provided date string to user date
$user_date = date('Y-m-d H:i:s', strtotime($date_string));

# convert user date to utc date
$utc_date = Carbon::createFromFormat('Y-m-d H:i', $user_date, $user->timezone);
$utc_date->setTimezone('UTC');

# check the utc date
dd($utc_date);

Convert UTC time to User time

# using utc date convert date to user date
$user_date = Carbon::createFromFormat('Y-m-d H:i', $utc_date, 'UTC');
$user_date->setTimezone($user->timezone);

# check the user date
dd($user_date);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文