PHP Learning Section 14

Now learn the time function in php .

PHP's date() function is used to format time or date.

PHP Date() function

The PHP Date() function formats the timestamp into a more readable date and time.

grammar

date(format,timestamp)
Parameter Description
format Required. Specifies the format of the timestamp.
timestamp Optional. Specifies the timestamp. The default is the current date and time.

PHP Date - What is a Timestamp?

The timestamp is the number of seconds since January 1, 1970 (00:00:00 GMT). It is also known as Unix Timestamp.

PHP Date - formatted date

The first parameter of the date() function specifies how to format the date/time. It uses letters to represent the format of date and time. Here are some available letters:

  • d - day of the month (01-31)
  • m - the current month, as a number (01-12)
  • Y - the current year (four digits)

You can find all the letters that can be used in format parameters in our PHP Date reference manual.

Additional characters such as "/", ".", or "-" can be inserted between letters to add additional formatting:

<?php
echo date("Y/m/d");
echo "<br />";
echo date("Y.m.d");
echo "<br />";
echo date("Y-m-d");
?>

The output of the above code looks like this:

2006/07/11
2006.07.11
2006-07-11

PHP Date - Add Timestamp

The second parameter of the date() function specifies a timestamp. This parameter is optional. If you don't 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 the specified date.

grammar

mktime(hour,minute,second,month,day,year…………………………………………………………………………

Detailed page: http://www.verydemo.com/demo_c170_i747.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326565967&siteId=291194637