简体   繁体   English

在php中显示当前星期的1、2、3、4和5日

[英]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.

相关问题 PHP日期和时间,在一个月内获得第1周,第2周,第3周和第4周 - PHP Date and Time, getting the 1st, 2nd, 3rd, and 4th week in a month 如何在选项标签 select 下拉列表 1st 2nd 3rd 4th 5th 中添加上标。 1ST 我想要 S 大写字母,但我试过 s 将转换为小写 - How to add superscript in option tag select dropdown 1st 2nd 3rd 4th 5th. 1ST I want S captial letters but i tried s will converted to small case 如何对数组中的每个第二,第三和第五个元素进行运算? - How to operate on every 2nd, 3rd and 5th element in an array? 如何根据学生的分数来使其排名(第,第2,第3,第4) - How to make Students Position (ist, 2nd, 3rd, 4th) depending on their scores 如何使用PHP在JSON数组中打印第1,第3,第5个元素 - How to print 1st,3nd,5th elements in JSON array using PHP 使用碳查找一周中的每一天 [1st,2nd,3rd] 对于接下来的 15 天 - Find every [ 1st,2nd,3rd ] day of week using carbon For next 15 day 如何确定星期几在一个月中的第一,第二,第三等发生? - How to determine if day of week is 1st, 2nd, 3rd, etc occurrence in a month? 在代码点火器中显示前10个结果,并显示第1,第2和第3个最高值 - Display top 10 results in codeigniter and display 1st, 2nd and 3rd top values 如果今天的日期在12月1日至1月5日之间 - IF todays date is between 1st December and 5th January MySQL - mysql日期格式后缀(第1,第2,第3 ......) - MySQL - mysql date format suffix (1st, 2nd, 3rd…)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM