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

藏色散人
Release: 2023-03-12 18:56:02
Original
5418 people have browsed it

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

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!

Related labels:
php
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