This question already has an answer here:
这个问题已经有了答案:
- Get first day of week in PHP? 35 answers
- 在PHP中获得第一天?35的答案
im trying to get the first day of a given week based on inputting a week number and year. im currently using this for the current week and year and works like a charm.
我试着输入一个星期的数字和年份来得到一个星期的第一天。我现在在这周和这一年都在使用它,它就像一种魅力。
$week = date('W');
$year = date('Y');
$date1 = date('Y-m-d', strtotime($year."W".$week.'1'));
however when i try to input my own week and year it doesn't work
然而,当我尝试输入我自己的一周和一年的数据时,它就不管用了
$week = 7;
$year = 2013;
$date1 = date('Y-m-d', strtotime($year."W".$week.'1'));
what type if string should i be using for strtotime? how come providing my own date doesn't work?
strtotime应该使用什么类型的字符串?为什么提供我自己的约会不成功?
1 个解决方案
#1
7
Because the week numbers are supposed to be padded (and the extra 1
at the end doesn't really do anything):
因为这周的数字应该是padd(而最后的额外的1并没有什么作用):
$date1 = date(
'Y-m-d',
strtotime($year . 'W' . str_pad($week, 2, '0', STR_PAD_LEFT))
);
#1
7
Because the week numbers are supposed to be padded (and the extra 1
at the end doesn't really do anything):
因为这周的数字应该是padd(而最后的额外的1并没有什么作用):
$date1 = date(
'Y-m-d',
strtotime($year . 'W' . str_pad($week, 2, '0', STR_PAD_LEFT))
);