Home >Backend Development >PHP Problem >How to get the day of the week based on date in php
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.
#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!