PHP date() date function
PHP date() function
PHP date() function is used to format time/date.
PHP date() function
PHP date() function formats timestamps for readability Better date and time.
A timestamp is a character sequence that represents the date/time when a certain event occurred.
Syntax
string date ( string $format [, int $timestamp ] )
Parameters Description
format Specifies the format of the timestamp.
timestamp Optional. Specify timestamp. The default is the current date and time.
PHP Date() - Formatted date
The first required parameter format of the date() function is specified How to format date/time.
Here are some available characters:
· d - represents the day of the month (01 - 31)
· m - represents the month (01 - 12)
· Y - represents the year (four digits)
For a list of all characters available in the format parameter, please consult our PHP Date reference manual, date() function.
You can insert other characters between letters, such as "/", "." or "-", so that you can add additional formats:
<?php echo date("Y/m/d") . "<br>"; echo date("Y.m.d") . "<br>"; echo date("Y-m-d"); ?>
The format string can recognize the following formats. Parameter string
<?php echo "date()函数输出格式化日期:<br />"; // 常用 echo date("l") . "<br />";// 注意是字符L的小写,不是1,也不是竖线 echo date("Y-m-d H:i:s") . "<br />"; echo date("Y/m/d") . "<br />"; echo date("Y年m月d日 H时i分s秒") . "<br />"; // 从日期格式的字符串中获取日期2005-03-21 echo date("Y-m-d",strtotime("2005-03-21 11:15:38"))."<br />"; echo date("Y-m-d",strtotime("-1 days"))."<br />";// 昨天的日期 echo date("Y-m-d",strtotime("-1 week"))."<br />";// 上个星期今天的日期 echo date("Y-m-d",strtotime("-1 month"))."<br />";// 上个月今天的日期 echo date("Y-m-d H",strtotime("next Thursday"));// 下个周四的日期和小 echo date('Y-m-d',strtotime('2015-06-08 -2 days')); // 某个日期的前n天 ?>Full PHP Date reference Manual