Home>Article>Backend Development> How to determine the day of the week based on timestamp in php
php method to determine the day of the week based on the timestamp: 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 method is: [date("Y/m/d")].
Function introduction:
(Recommended tutorial:php graphic tutorial)
PHP date () function formats a timestamp into a more readable date and time.
Function syntax:
string date ( string $format [, int $timestamp ] )
Parameters:
format Required. Specifies the format of the timestamp.
#timestamp Optional. Specify timestamp. The default is the current date and time.
(Video tutorial recommendation:php video tutorial)
Available character introduction:
d - represents the day of the month (01 - 31)
m - represents the month (01 - 12)
Y - represents Year (four digits)
#w - Day of the week, expressed as a number. 0 (meaning Sunday) to 6 (meaning Saturday)
Code implementation:
function getTimeWeek($time, $i = 0) { $weekarray = array("一", "二", "三", "四", "五", "六", "日"); $oneD = 24 * 60 * 60; return "周" . $weekarray[date("w", $time + $oneD * $i)]; } $time=time(); echo getTimeWeek($tiem);
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!