Home > Article > Backend Development > How to convert timestamp to date format in php
In PHP, you can use the date function to convert the timestamp into date format, with code such as "date("Y-m-d H:i:s",$coupon.use_start_time)".
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to convert timestamp to date format in php?
Time stamp to date date()
For example
date("Y-m-d H:i:s",$coupon.use_start_time)
{$coupon.use_start_time|date='Y-m-d H:i:s',###}
date — Formatting A local time/date
Description
date(string $format, int $timestamp = ?): string
Returns a string generated by converting the integer timestamp according to the given format string. If no timestamp is given, the local current time is used. In other words, timestamp is optional and the default value is time().
Tips
Since PHP 5.1.1 there are several useful constants that can be used to specify the format parameter in standard date/time formats.
Tips
Since PHP 5.1, the timestamp of the time when the request was initiated is saved in $_SERVER['REQUEST_TIME'].
Note:
The typical range of valid timestamps is December 13, 1901 20:45:54 GMT to January 19, 2038 03:14:07 GMT. (This range conforms to the minimum and maximum values of 32-bit signed integers). However, prior to PHP 5.1 this range was limited to January 1, 1970 to January 19, 2038 on some systems such as Windows.
Note:
To convert the time expressed in a string into a timestamp, strtotime() should be used. Additionally some databases have functions to convert their time format into timestamps (e.g. MySQL's » UNIX_TIMESTAMP function).
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert timestamp to date format in php. For more information, please follow other related articles on the PHP Chinese website!