php如何存储星期一到下个6个月的星期五从明天开始的数组

时间:2017-04-02 15:34:41

标签: php html

我正在制作一个页面让客户选择约会日期,所以我需要建立一个这样的日期列表:
enter image description here

  • 总是从明天开始,以6个月结束
  • 总是从蒙迪到星期六,没有星期天
  • 星期几需要用中文,比如“星期一”是“星期一”,但时区是在法国

这是php

date_default_timezone_set('Europe/Paris');

$tomorrow = date("Y年m月d日 l", time() + 86400);
$end = date("Y年m月d日 l", time() + 86400 * 7); // just 7 days for a try 
$interval = new DateInterval('P1D');

$daterange = new DatePeriod($tomorrow, $interval, $end);

foreach ($daterange as $date) {
    echo $date . '<br/>';
}

此代码无效。 我需要建立一个阵列,存储未来6个月的所有日期,从明天开始,没有星期天,需要使用中文,时区需要在欧洲,这可能吗?

1 个答案:

答案 0 :(得分:1)

我认为strtotime和array_push是您正在寻找的。试试这个:

$curDate = date('Y-m-d', strtotime('+1 day'));
$endDate = date('Y-m-d', strtotime('+6 months +1 day'));

$myArr = array();
while ($endDate >= $curDate) {
    if (date('w', strtotime($curDate)) !== '0') array_push($myArr, $curDate);
    $curDate = date('Y-m-d', strtotime($curDate . " +1 days"));
}

var_dump($myArr);

对于选项,从星期日到星期六创建一个数组。

$weekdays = array('Sunday', ..., 'Saturday');
echo date('Y/m/d', strtotime($curDate)) . ' ' . $weekdays[date('w', strtotime($curDate))];
相关问题