PHP date format turn timestamp _php tutorial

Source: Internet
Author: User
Tags echo date
PHP provides functions that can easily convert various forms of a date to a timestamp, which is mainly:

    • Strtotime (): Resolves the datetime description of any English text to a timestamp.
    • Mktime (): Gets the timestamp from the date.

Strtotime ()

The Strtotime () function is used to convert the date represented by the English text string to a timestamp, an inverse of date (), which returns the timestamp successfully, otherwise FALSE. Grammar:

int Strtotime (string time [, int now])

The parameter time is the parsed string and is the date represented by the GNU date input format.

Example:

 
  ";//output The timestamp of the present time tomorrow?>

Mktime ()

The Mktime () function is used to obtain a timestamp from a date, successfully returning a timestamp, or FALSE. Grammar:

int Mktime (time, minute, second, month, day, year)

Example:

 
  

Parameters can be omitted from right to left, and any omitted parameters are set to the current value of the cost date and time.

Mktime () is useful for date calculation and validation, and it automatically calculates the correct value for an out-of-range input. For example, the following example output is 2008-01-01:

 
  

The last day of next month. The last day of any given month can be represented as the "0" day of the next month, not 1 days, as in the following example:

 
  

Custom functions

The following function is similar to the Strtotime function.

 
  echo Date ("Y-m-d h:i:s", $time _str);? >

http://www.bkjia.com/PHPjc/752397.html www.bkjia.com true http://www.bkjia.com/PHPjc/752397.html techarticle PHP provides functions that can easily convert various forms of a date to a timestamp, which is mainly: Strtotime (): Resolves the datetime description of any English text to a timestamp. ...

  • Related Article

    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.