PHP timestamp and how to convert between dates

Source: Internet
Author: User
Tags time and date timestamp to date
The conversion between timestamp and date in PHP is achieved through the data () function and the Strtotime () function, and the data function implements the timestamp to date, and the Strtotime function implements the date-to-time stamp.

Timestamp to date ()

    • Time ()

<?phpvar_dump (Time ()); Gets the current timestamp int (1502245603)
    • Date (Format,timestamp)

Format required. Specifies the format of the timestamp.
Timestamp is optional. Time stamp is specified. The default is the current time and date

Timestamp to date can be implemented with date (' Y-m-s h:i:s ', specific timestamp).

Y: Year (four-digit) uppercase
M: Month (two digits, first less than 0) lowercase
D: Day (two digits, first less than 0) lowercase
H: Hour with first zero 24 hour format
H: Hour with First zero 12 hour format
I: minutes with first zero
S: Seconds with First zero (00-59)
A: Lowercase noon and afternoon (AM or PM)

Case sensitivity is important, such as the following example:

Var_dump (Date (' y-m-d h:i:s ', 1502204401)); H 24-hour 2017-08-08 23:00:01 var_dump (Date (' y-m-d h:i:s ', 1502204401)); H 12-hour 2017-08-08 11:00:01

Date turn timestamp strtotime ()

Strotime is a very flexible and intelligent function that can recognize Chinese, English, and digital, let's feel it.

<?phpecho strtotime ("Now"), "\ n", Echo Strtotime ("Ten September"), "\ n"; Echo strtotime ("+1 Day"), "\ n"; Echo Strtotime ("+1 Week"), "\ n"; Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds"), "\ n"; Echo strtotime ("next Thursday"), "\ n"; Echo Strtotime ("Last Monday"), "\ n"; Echo strtotime ("20170808 23:00:01"), "\ n";? >

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.