php Date conversion method: 1. Convert timestamp to date through syntax "date(format, timestamp)"; 2. Convert date to timestamp through "strtotime()" method.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.
PHP timestamp and date conversion
Time stamp to date date()
date(format,timestamp)
format Required. Specifies the format of the timestamp.
timestamp Optional. Specify timestamp. The default is the current time and date
For example: date('Y-m-d H:i:s', specific timestamp)
Y: Year (four digits) in uppercase letters
m: Month (two digits, add 0 if the first digit is missing) Lowercase
d: Day (two digits, add 0 if the first digit is missing) Lowercase
H: hour with a leading zero 24 hours Hour format
h: hour 12 hours with leading zero Hour format
i: minute with leading zero
s: second with leading zero (00 -59)
a: Lowercase noon and afternoon (am or pm)
The distinction between upper and lower case is very important, such as the following example:
var_dump(date('Y-m-d H:i:s', 1502204401)); //H 24小时制 2017-08-08 23:00:01 var_dump(date('Y-m-d h:i:s', 1502204401)); //h 12小时制 2017-08-08 11:00:01
Recommended: "PHP video tutorial》
Date to timestamp strtotime()
strotime is a very flexible and smart function that can recognize Chinese, English, and numbers. We Come and feel it
<?php echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n"; echo strtotime("20170808 23:00:01"), "\n"; ?>
The above is the detailed content of What is the php date conversion method?. For more information, please follow other related articles on the PHP Chinese website!