php - list of dates coming up

非 Y 不嫁゛ 提交于 2019-12-11 16:52:33

问题


All the users are in the United States. I need to be able to list all weekdays besides today. So say that it's Thursday, October 7. It should start by listing Friday, October 8 and then Monday, October 11.

I know how to make sure I'm only listing weekdays when looping through, but the trouble I have is making sure tomorrow is tomorrow. In the past it's changed at about 8:00 at night eastern time. I'm thinking I'd like to have is so when it's maybe 12:00 pacific time to count it as the next day.


回答1:


<?php
   $current = new DateTime('now');
   $last = new DateTime('saturday');
   while ($current < $last) {
      echo $current->format('l, F j'), "\n";
      $current->modify('+1 day');
   }
?>



回答2:


You can use strtotime to get the date of the next days and you can use date to determine if a date is a week day :

<?php
$reference = time(); // We set today as the first day //

for ($i=0, $j=0; $i<5; $i++, $j++) {
   $nextDay = strtotime('+' . $j . ' days', $reference);
   if (date('w', $nextDay) > 0 && date('w', $nextDay) < 6) {
       echo date('r', $nextDay), "\n";
   } else {
       $i--;
   }
}
?>


来源:https://stackoverflow.com/questions/3875298/php-list-of-dates-coming-up

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!