When we explain how to get the current timestamp instance, we use the date() function to get the current time and date. In this chapter, we will introduce it to you. The "date" function that gets the current date and time.
Usage of date function
In PHP, use the date() function to obtain the current time and date. Its syntax format is as follows
date(format,timestamp);
date The () function will return a string generated by the timestamp parameter according to the specified format. The timestamp parameter is optional. If not written, the current time will be used. The format parameter allows developers to output dates in the format they specify. Regarding format parameters, we have written a special article. You can check it here //m.sbmmt.com/php-weizijiaocheng-360500.html.
Here are several predefined constants for time and date, as shown in the following table. These constants provide standard date expression methods and can be used for date format functions.
Predefined constants about time and date
Predefined constants | Description |
DATE_ATOM | Atomic Clock Format |
DATE_COOKIE | HTTP Cookies Format |
ISO-8601 format | |
RFC822 format | |
RFC850 format | |
WORSS format | |
World Wide Web Consortium format |
date function example one
This example Let me demonstrate the usage of the date() function. The code is as follows<?php header("Content-type:text/html;charset=utf-8"); //设置编码 echo "Now:".date("Y-m-d")."<br/>"; //输出当前日期 ?>
Date function example two
This example will compare the output of each constant. The sample code is as follows<?php echo "DATE_ATOM=".date(DATE_ATOM)."<br/>"; echo "DATE_COOKIE=".date(DATE_COOKIE)."<br/>"; echo "DATE_ISO8601=".date(DATE_ISO8601)."<br/>"; echo "DATE_RFC822=".date(DATE_RFC822)."<br/>"; echo "DATE_RFC850=".date(DATE_RFC850)."<br/>"; echo "DATE_RSS=".date(DATE_RSS)."<br/>"; echo "DATE_W3C=".date(DATE_W3C ); ?>
The above is the detailed content of Detailed explanation of PHP date() function to obtain the current date and time instance. For more information, please follow other related articles on the PHP Chinese website!