Home >Backend Development >PHP Problem >How to determine what day of the week a specified date is in php?
Method: First define the array of "array("日","一","二","三","四","五","六")"; then use "date( "w",strtotime("specified date"))" converts the date into a number representing the week; finally, use the number as a subscript and retrieve the corresponding week value from the array.
Recommended: "PHP Video Tutorial"
php method to determine the day of the week for a specified date
<?php header('content-type:text/html;charset=utf-8'); $weekarray=array("日","一","二","三","四","五","六"); echo "星期".$weekarray[date("w",strtotime("2020-11-4"))]."<br>"; echo "星期".$weekarray[date("w",strtotime("2020-10-1"))]; ?>
Output:
星期三 星期四
w format of date() function: Use numbers to represent the day of the week, 0 (representing Sunday) to 6 (representing Saturday)
php determines what day of the week it is today:
<?php header('content-type:text/html;charset=utf-8'); $weekarray=array("日","一","二","三","四","五","六"); echo "今天是星期".$weekarray[date("w")]; ?>
Output:
今天是星期四
More programming For related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of How to determine what day of the week a specified date is in php?. For more information, please follow other related articles on the PHP Chinese website!