Home  >  Article  >  Backend Development  >  How to get the day of the week based on date in php

How to get the day of the week based on date in php

藏色散人
藏色散人Original
2021-09-19 16:14:445437browse

php method to get the day of the week based on date: 1. Create a PHP sample file; 2. Set "$weekarray"; 3. Pass "$weekarray[date("w",strtotime("... "))];" can be used to obtain the day of the week corresponding to the specified date.

How to get the day of the week based on date in php

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

How to get the day of the week based on the date in php?

PHP gets the day of the week based on the current date

The code is as follows:

$weekarray=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; 
echo $weekarray[date("w",strtotime("2018-10-6"))];
echo $weekarray[date("w",time())];

date() function formats the local date and time and returns the formatted date String.

The strtotime() function parses any English text date or time description into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT).

The time() function returns the number of seconds since the Unix epoch (January 1 1970 00:00:00 GMT).

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to get the day of the week based on date 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