我不是一个PHP编码器,然而,似乎strtotime是你所追求的.
你可以使用strtotime("第四个星期六"),它将在第四个星期六返回.
查看strtotime文档.
编辑:
感谢Tom和Paul Dixon,只是为了完成答案
date('dS F',strtotime('Fourth Saturday '.date('F o')));
Run Code Online (Sandbox Code Playgroud)
您可以使用strtotime根据开始日期查找"下周六".如果该开始日期是在最早可能的前一天(21日)之前的那一天,我们得到答案......
//required year/month
$yyyymm="2009-01";
//find next saturday after earliest possible date
$t=strtotime("next saturday", strtotime("{$yyyymm}-21"));
//here you go!
echo "4th saturday of $yyyymm is ".strftime("%Y-%m-%d",$t)."\n";
Run Code Online (Sandbox Code Playgroud)
任何一个月中最早可能的第四次重复是第22次(1,8,15,22),最后可能的第4次重复是第28次(7,14,21,28).
编辑:虽然在文档中不清楚,您也可以请求"第四个星期六" - 使用该月的第0天作为基础:
$t=strtotime("fourth saturday", strtotime("{$yyyymm}-00"));
Run Code Online (Sandbox Code Playgroud)
或省略基准时间并直接指定月份和年份:
$t=strtotime("fourth saturday feb 2009");
Run Code Online (Sandbox Code Playgroud)
罗宾的帽子提示"我不是PHP编码器"发现的那天:)
| 归档时间: |
|
| 查看次数: |
2477 次 |
| 最近记录: |