Home > Article > Backend Development > 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('UTC');
// 输出类似:Monday
echo date("l");
// 输出类似:Monday 15th of August 2005 03:12:46 PM
echo date('l dS \of F Y h:i:s A');
// 输出: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));
?> 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!