Php date function

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.