Home >Backend Development >PHP Problem >How to determine the day of the week in php

How to determine the day of the week in php

王林
王林Original
2020-07-21 16:19:276745browse

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.

How to determine the day of the week in php

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!

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