在工作中遇到获取当前星期,于是就写了一个:
<?php function getWeek($date,$num){ if($num==1){ return date("w",strtotime($date)); } else if($num==2){ $weekarray=array("日","一","二","三","四","五","六","日"); return "周".$weekarray[date("w",strtotime($date))]; } } echo getWeek(date("y-m-d",time()),1); echo "<br/>"; echo getWeek(date("y-m-d",time()),2); ?>
其中第二个参数是用来获取不同的日期形式。
注意:星期是从周日开始的,如果是星期日,会返回0,不会返回7