Php如何获得替代周日期

时间:2014-01-06 05:36:16

标签: php date

我想显示当月的替代周日期。假设今天是本周三。所以我想显示本周一至周五的日期。我想在接下来的下一周(跳过一周)也一样。所以我想要

  • 1月6日至1月11日
  • 1月20日至1月24日

  • 1月13日至1月18日
  • 1月27日至1月31日(替代周)

(这些日期在2014年的背景下描述)

1 个答案:

答案 0 :(得分:0)

<?php

$date = new DateTime();


echo $date->format('dS M'); // today
echo "<br />";

$date->modify('this week'); // reset to firstday of the week, Monday
echo $date->format('dS M');
echo "<br />";

$date->modify('+1 day'); // add 1 day with current stored date
echo $date->format('dS M');
echo "<br />";

$date->modify('next week'); // go to next week
$date->modify('next week'); // doing this second time will add another week
echo $date->format('dS M'); // print first day of that week

Demo