如何在特定时区的php中查找星期几

我在使用php处理日期/时间时感到困惑。

我想做的是:当用户访问我的页面时,我询问他的时区,然后在他的时区中显示“星期几”。

我不想用浏览器的一天。我想在php中进行此计算。

这就是我试图实现的方式:

  1. 用户输入的时区

  2. 通过php time()函数计算的Unix时间戳。

但我不知道该如何进行...在该时区我将如何获得“一周中的某天”。


慕容708150
浏览 367回答 3
3回答

aluckdog

我的解决方案是这样的:$tempDate = '2012-07-10';echo date('l', strtotime( $tempDate));输出为: Tuesday$tempDate = '2012-07-10';echo date('D', strtotime( $tempDate));输出为: Tue

幕布斯7119047

非常感谢您的快速评论。这就是我现在将要使用的。在此处发布函数,以便有人可以使用它。public function getDayOfWeek($pTimezone){    $userDateTimeZone = new DateTimeZone($pTimezone);    $UserDateTime = new DateTime("now", $userDateTimeZone);    $offsetSeconds = $UserDateTime->getOffset();     //echo $offsetSeconds;    return gmdate("l", time() + $offsetSeconds);}报告是否发现任何更正。
打开App,查看更多内容
随时随地看视频慕课网APP