Home >Backend Development >PHP Problem >How to determine what day of the week a specified date is in php?

How to determine what day of the week a specified date is in php?

青灯夜游
青灯夜游Original
2020-11-05 16:56:113637browse

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.

How to determine what day of the week a specified date is in php?

Recommended: "PHP Video Tutorial"

php method to determine the day of the week for a specified date

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$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(&#39;content-type:text/html;charset=utf-8&#39;);
$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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn