[PHP]获取当天或指定日期属于星期几

文章目录[隐藏]

示例代码

<?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": "星期五" }

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据