Home>Article>Backend Development> How to determine the day of the week based on timestamp in php

How to determine the day of the week based on timestamp in php

王林
王林 Original
2020-08-01 13:15:27 3206browse

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")].

How to determine the day of the week based on timestamp in php

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!

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