Home > Backend Development > PHP Problem > How to convert timestamp to date in PHP

How to convert timestamp to date in PHP

Guanhui
Release: 2023-03-01 08:12:01
Original
2999 people have browsed it

How to convert timestamp to date in PHP

How does PHP convert a timestamp into a date?

In PHP, you can use the "date()" function to convert a timestamp into a date. This function Used to format a local time date, its syntax is "date($format,$timestamp)", its parameter format represents the date format, and the parameter timestamp represents the timestamp to be formatted.

Code example:

<?php
// 设定要用的默认时区。自 PHP 5.1 可用
date_default_timezone_set(&#39;UTC&#39;);


// 输出类似:Monday
echo date("l");

// 输出类似:Monday 15th of August 2005 03:12:46 PM
echo date(&#39;l dS \of F Y h:i:s A&#39;);

// 输出:July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

/* 在格式参数中使用常量 */
// 输出类似:Wed, 25 Sep 2013 15:28:57 -0700
echo date(DATE_RFC2822);

// 输出类似:2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>
Copy after login

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to convert timestamp to date 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template