[英]Display the 1st, 2nd, 3rd, 4th, & 5th date of the current week in php
Ok, So im trying to figure out the best way in php to write (or print) the 1st, 2nd, 3rd, 4th, & 5th date of the current week (starting with Monday) in php. 好的,所以我想找出用php编写(或打印)当前星期(从星期一开始)的第1、2、3、4和5日的最佳方法。
For example... Using the week of the 4th through the 8th of February... 例如...使用2月4日至8月的星期...
I would need a script for the 1st day of the week (starting with Monday) displayed as February 04, 2013 and then I would need the same script four more times to display Tues, Wed, Thurs, & Fri... 我需要在一周的第一天(从星期一开始)显示为2013年2月4日的脚本,然后再需要四次相同的脚本来显示周二,周三,周四和周五...
All-together I would end up with 5 scripts or one script that I could copy and manipulate to work the way I need it to... 总的来说,我最终会得到5个脚本或一个脚本,可以按照自己需要的方式对其进行复制和操作...
Also, If you could tell me how to do the same for Saturday and Sunday that would be greatly appreciated as-well. 另外,如果您能告诉我在周六和周日该如何做,那也将不胜感激。
If there is anything that you do not understand, please let me know and I will try my hardest to clarify... 如果您不了解任何内容,请告诉我,我们将尽力澄清...
Thanks in advance! 提前致谢!
First you need to get the "current" week's Monday. 首先,您需要获取“当前”星期的星期一。 To do this, I would suggest calling
date("N")
and see if it's 1. If it is, then now
is the Monday you want. 为此,我建议调用
date("N")
,看看它是否为1。如果是,那么now
就是您想要的星期一。 Otherwise last monday
is. 否则,
last monday
一是。 Pass that to strtotime
to get the timestamp corresponding to the first monday of the week. 将其传递给
strtotime
以获得对应于一周的第一个星期一的时间戳。 Then repeatedly add 24 hours (24*3600 seconds) to get each day. 然后重复添加24小时(24 * 3600秒)以获取每天的收益。
$startofweek = date("N") == 1 ? time() : strtotime("last monday");
for($i=0; $i<5; $i++) {
$day = $startofweek + 24*3600*$i;
echo "Day ".($i+1).": ".date("d/M/Y",$day)."<br />";
}
You can use strtotime with special parameters. 您可以将strtotime与特殊参数一起使用。 like:
喜欢:
$time = strtotime('monday this week');
$time = strtotime('today');
$time = strtotime('next monday');
$time = strtotime('previous monday');
Same goes for every other days of the week 一周的其他几天都一样
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.