本文介绍了DateTime的YearWeek的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从PHP中的DateTime获取YearWeek:
I would like to get YearWeek from DateTime in PHP:
$day = \DateTime ...
$YearWeek = date("YW", date_timestamp_get($day));
但是如果一周是两年,它将不起作用:
But in case the week is on two years, it does not work:
$day // 2017-01-01
$YearWeek // I get 201752 instead of 201652
我该怎么办?
推荐答案
在的手册中,使用 o
而不是 Y
:
From the manual for date(), use o
instead of Y
:
$day = strtotime('2017-01-01');
echo date("YW", $day); //201752
echo date("oW", $day); //201652
这篇关于DateTime的YearWeek的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!