【问题标题】:How to get the month in date changed with according to user timezone in php如何根据php中的用户时区更改日期月份
【发布时间】:2021-07-12 10:36:56
【问题描述】:

我在 php 中尝试了如下日期时间

    $datetime           = new \DateTime(''2021-03-23 11:20:15.000000'');
    $datetimeZone       = $datetime->setTimezone(new \DateTimeZone('UTC'));
    $datetimeZoneFormat = $datetimeZone->format('F, d Y');

我从中得到一个输出

“2021 年 4 月 10 日”

但我希望根据用户的时区更改月份

例如:

如果用户来自法国,我希望日期时间为 "Avril, 10 2021"

如果用户来自西班牙,我希望日期时间为 "Abril, 10 2021"

有人可以帮我解决这个问题吗?我对这项技术还很陌生?

【问题讨论】:

标签: php datetime format timezone utc


【解决方案1】:

成功了。谢谢

$datetime           = new \DateTime(''2021-03-23 11:20:15.000000'');
$datetimeZone       = $datetime->setTimezone(new \DateTimeZone('UTC'));
$datetimeZoneFormat = ucwords(strftime('%B %e, %Y', $datetimeZone->getTimestamp()));

我不得不使用 strftime 函数并传递时间戳来实现我想要的结果,而不是格式函数

【讨论】:

    猜你喜欢
    • 2015-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2013-09-23
    • 2014-01-30
    • 1970-01-01
    相关资源
    最近更新 更多