The way PHP determines the day of the week is: you can use the date() function to determine. The date() function can format the timestamp into a more readable date and time. The specific usage is as follows: [date("w");], where w represents the day of the week, 0 represents Sunday, and 6 represents Saturday.
The PHP date() function formats a timestamp into a more readable date and time.
(Recommended tutorial: php tutorial)
Function syntax:
string date ( string $format [, int $timestamp ] )
Parameter description:
format Required. Specifies the format of the timestamp. w represents the day of the week, 0 (representing Sunday) to 6 (representing Saturday).
timestamp Optional. Specify timestamp. The default is the current date and time.
Code implementation:
$ga = date("w"); switch( $ga ){ case 1 : echo "今天是星期一";break; case 2 : echo "今天是星期二";break; case 3 : echo "今天是星期三";break; case 4 : echo "今天是星期四";break; case 5 : echo "今天是星期五";break; case 6 : echo "今天是星期六";break; case 0 : echo "今天是星期日";break; default : echo "你输入有误!"; };
The above is the detailed content of How to determine the day of the week in php. For more information, please follow other related articles on the PHP Chinese website!