Home>Article>Backend Development> How to determine the day of the week based on timestamp in php
In PHP, you can use the date() function to determine the day of the week based on the timestamp. This function can format the timestamp into a readable date and time string; the syntax format is "date("w ",timestamp);", "w" specifies that the timestamp be formatted as a number representing the day of the week, 0 represents Sunday, 6 represents Saturday.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can date( ) function to determine the day of the week based on the timestamp.
date() function formats the local date and time and returns the formatted date string.
Syntax:
date(format,timestamp);
When format is set to "w", you can specify that the timestamp is formatted as a number representing the day of the week, (0 represents Sunday [Sunday], 6 represents Saturday [Saturday] ]).
Output:
6
Let’s optimize the code:
"; $time=strtotime("2021-09-25"); $week = $weekarray[date("w",$time)]; echo "周".$week; ?>
Output:
Recommended learning : "PHP Video Tutorial"
The above is the detailed content of How to determine the day of the week based on timestamp in php. For more information, please follow other related articles on the PHP Chinese website!