In php, you can format the date and time by setting the parameters in the data function to obtain the time and date
[Recommended course:PHP Tutorial】
You can use the date() function to compare dates in PHP formatted with time. The first parameter in the data function specifies how to format the date and time. It uses letters to represent date and time
The syntax of the data function:
date(format,timestamp)
where format represents the format of the time, and timestamp represents the specified time, by default The following refers to the current time and date
Here are some commonly used date characters
d: represents a certain day of the month (01-31)
m: Indicates the month (01-12)
Y: Indicates the year (four digits)
1: Indicates a day of the week
h : 12-hour hour format with leading zero
i : Minutes with leading zero
s : Seconds with leading zero (00 -59)
a : Lowercase noon and noon (am or pm)
Other characters, such as "/", "." or "-" can also be inserted into the characters to add other formats.
Specific usage of the data() function:
Get the current date and time
Rendering:
Note: When using PHP5.3 or above, if the php.ini file is not configured correctly, an error in the PHP date function will occur. So we need to add a line of date_default_timezone_set('PRC'); code in front of php. The purpose is to make it enter the correct date time.
Get the number of days in a certain time
Rendering:
Summary: The above is about the data How to use it, I hope it will be helpful to everyone.
The above is the detailed content of How to use data function in php. For more information, please follow other related articles on the PHP Chinese website!