我在使用php处理日期/时间时感到困惑。我想做的是:当用户访问我的页面时,我询问他的时区,然后在他的时区中显示“星期几”。我不想用浏览器的一天。我想在php中进行此计算。这就是我试图实现的方式:用户输入的时区通过php time()函数计算的Unix时间戳。但我不知道该如何进行...在该时区我将如何获得“一周中的某天”。
3 回答
aluckdog
TA贡献1847条经验 获得超7个赞
我的解决方案是这样的:
$tempDate = '2012-07-10';
echo date('l', strtotime( $tempDate));
输出为: Tuesday
$tempDate = '2012-07-10';
echo date('D', strtotime( $tempDate));
输出为: Tue
幕布斯7119047
TA贡献1794条经验 获得超8个赞
非常感谢您的快速评论。
这就是我现在将要使用的。在此处发布函数,以便有人可以使用它。
public function getDayOfWeek($pTimezone)
{
$userDateTimeZone = new DateTimeZone($pTimezone);
$UserDateTime = new DateTime("now", $userDateTimeZone);
$offsetSeconds = $UserDateTime->getOffset();
//echo $offsetSeconds;
return gmdate("l", time() + $offsetSeconds);
}
报告是否发现任何更正。
- 3 回答
- 0 关注
- 361 浏览
添加回答
举报
0/150
提交
取消