PHP 获取指定日期星期几

时间:2021-08-11 13:58:47

<?php

 

function   wk($date1) {
$datearr = explode("-",$date1);     //将传来的时间使用“-”分割成数组
$year = $datearr[0];       //获取年份
$month = sprintf('%02d',$datearr[1]);  //获取月份
$day = sprintf('%02d',$datearr[2]);      //获取日期
$hour = $minute = $second = 0;   //默认时分秒均为0
$dayofweek = mktime($hour,$minute,$second,$month,$day,$year);    //将时间转换成时间戳
$shuchu = date("w",$dayofweek);      //获取星期值
$weekarray=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
echo $weekarray[$shuchu];
}

 

$day1='2011-04-13';

wk($date1);

 

?>

 

输出结果为:星期三