我如何找到PHP的当前月的最后一个星期六的星期几? [英] How do I find what day the last saturday of the current month is in PHP?

查看:86
本文介绍了我如何找到PHP的当前月的最后一个星期六的星期几?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此方法在大多数月份都有效,但例如,2011年4月有5个星期六,因此它返回23而不是30.

This works for most months, but for example, April 2011 has 5 saturdays, so this returns 23 instead of 30.

$last_saturday = date("j", strtotime('Fourth Saturday'.date('F o')));

推荐答案

last saturday在某些星座中似乎被解释为先前的星期六".

last saturday seems to be interpreted as "previous saturday" in some constellations.

这是在Windows 7上的PHP 5.3上对我有效的方法:跳至下个月的第一天,并寻找最后一个星期六.

This is what works for me on PHP 5.3 on Windows 7: Jump to next month's first day, and look for last saturday.

 $nextMonthStart = mktime(0,0,0,date('m')+1,1,date('Y'));
 $last_saturday = date("d.m.Y",strtotime("previous saturday", $nextMonthStart));

即使在下个月的第一天是星期六的情况下,我也能为我工作.

works for me even in the edge case that the first day of next month is a saturday.

这篇关于我如何找到PHP的当前月的最后一个星期六的星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆