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

王林
Release: 2023-03-02 19:54:01
Original
6762 people have browsed it

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 ] )
Copy after login

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 "你输入有误!"; 
};
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template