话不多说,直接上代码:
$year = '2020';
$week = date('W',strtotime(date('Y-m-d')));
$strPad = str_pad(9, 2, 0, STR_PAD_LEFT);
$rs = $year . 'W' . str_pad($week, 2, 0, STR_PAD_LEFT);
$Monday = date('Y-m-d', strtotime($rs));
$Sunday = date('Y-m-d', strtotime('+6 day', strtotime($Monday)));
var_dump($week,$strPad,$rs,$Monday,$Sunday);
string(2) "25"
string(2) "09"
string(7) "2020W25"
string(10) "2020-06-15"
string(10) "2020-06-21"
其中涉及函数,讲解:
date函数,W
str_pad函数:strtotime('2020W25'):
简单记下吧。