: This article mainly introduces the date function of php. if you are interested in the PHP Tutorial, refer to it. The date () function of PHP is used to format the time or date.
PHP Date () function
The PHP Date () function can format the timestamp as a Date and time with better readability.
Syntax
date(format,timestamp)
Parameters |
Description |
Format |
Required. The format of the specified timestamp. |
Timestamp |
Optional. The specified timestamp. The default value is the current date and time. |
PHP date-what is Timestamp )?
The timestamp is the number of seconds since January 1, 1970 (00:00:00 GMT. It is also called Unix Timestamp ).
PHP date-format date
The first parameter of the date () function specifies how to format the date/time. It uses letters to indicate the date and time formats. Some available letters are listed here:
- Day in d-month (01-31)
- M-current month, in numbers (01-12)
- Y-current year (four digits)
You can find all the letters that can be used in the format parameters in our PHP Date reference manual.
You can insert other characters between letters, such as "/", ".", or "-" to add additional formats:
";echo date("Y.m.d");echo "
";echo date("Y-m-d");?>
The output of the above code is similar to this:
2006/07/112006.07.112006-07-11
PHP date-add timestamp
The second parameter of the date () function specifies a timestamp. This parameter is optional. If you do not provide a timestamp, the current time will be used.
In our example, we will use the mktime () function to create a timestamp for tomorrow.
The mktime () function returns a Unix timestamp for a specified date.
Syntax
mktime(hour,minute,second,month,day,year,is_dst)
To obtain the timestamp of a certain day, we only need to set the day parameter of the mktime () function:
The output of the above code is similar to this:
Tomorrow is 2006/07/12
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the date function of php, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.