Home > Backend Development > PHP Problem > 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

王林
Release: 2023-03-03 17:06:02
Original
3355 people have browsed it

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

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

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!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template