示例代码
<?php
$Cache = new ESApi();
$json = $Cache->getWeekDay("2019-12-27");
echo json_encode($json,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
/**
* @param null $date
* @param bool $today
* @param bool $smple
* @return array
* @describe:获取当天或者指定日期是星期几
*/
class ESApi{
public function getWeekDay($date = null, $today = true, $smple = true){
$weekarray = ["日", "1", "2", "3", "4", "5", "6"]; //先定义一个数组
if ($smple == true) {
$weekarray = ["日", "一", "二", "三", "四", "五", "六"]; //先定义一个数组
}
$arr = [];
if ($today) {
$arr['Todayweek'] = "星期" . $weekarray[date("w")];
}
if (!empty($date)) {
$arr['Otherweek'] = "星期" . $weekarray[date("w", strtotime($date))];
}
return $arr;
}
}
返回数据
{ "Todayweek": "星期三", "Otherweek": "星期五" }
发表回复