When we explain how to get the currenttimestamp instance, we use thedate() functionto 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"; //输出当前日期 ?>
Date function example two
This example will compare the output of each constant. The sample code is as follows"; echo "DATE_COOKIE=".date(DATE_COOKIE)."
"; echo "DATE_ISO8601=".date(DATE_ISO8601)."
"; echo "DATE_RFC822=".date(DATE_RFC822)."
"; echo "DATE_RFC850=".date(DATE_RFC850)."
"; echo "DATE_RSS=".date(DATE_RSS)."
"; 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!