<?php
/**************************************本类功能说明******************************************/
//只需传入一个当天日期字符串,就可直接得到当天所在星期的整个星期每一天的日期字符串数组
/*******************************************END**********************************************/
class DateHelper
{
//传入的参数为日期字符串,如:2017-5-13
public function __construct($today)
{
$this->today=$today;
}
public function getTheWeek()
{
$todayTimestamp=strtotime($this->today);
$todayNumber=date('N',$todayTimestamp);
$oneDay=24*3600;
$weekNumRange=[1,2,3,4,5,6,7];
$theWeekDate=[];
$arr=array_keys($weekNumRange,intval($todayNumber),true);
$todayNumIndex=$arr[0];
$nowTimestamp=$todayTimestamp;
for($i=$todayNumIndex;$i<count($weekNumRange)-1;$i++){
$nowTimestamp+=$oneDay;
$theWeekDate[]=date('Y-m-d',$nowTimestamp);
}
array_unshift($theWeekDate,date('Y-m-d',$todayTimestamp));
$nowTimestamp=$todayTimestamp;
for($i=$todayNumIndex;$i>0;$i--){
$nowTimestamp-=$oneDay;
array_unshift($theWeekDate,date('Y-m-d',$nowTimestamp));
}
return $theWeekDate;
}
}
传入日期字符串输出日期星期几
最新推荐文章于 2023-07-02 15:25:25 发布