Php date, time-related knowledge, _ PHP Tutorial

Source: Internet
Author: User
Php date and time knowledge ,. Php date, time-related knowledge, unix timestamp: the number of seconds that have elapsed since, January 1, January 1, 1970 to the current time. 1. convert a date to a UNIX timestamp mktime (): you can automatically learn about php date and time,

Unix timestamp: the number of seconds that have elapsed since, January 1, January 1, 1970 to the current time.

1. convert a date to a UNIX timestamp
Mktime (): Automatically corrects out-of-range input.

Prototype: mktime (hour, minute, second, month, day, year );
Instance:

 

2. parse the date and time of English text into unix timestamp
Strtotime ()
Prototype: strtotime (time, now)

 

Example: use strtotime () to compile a countdown program for the anniversary

 

Extended: date calculation
The simplest way to calculate the length of the two dates is to calculate the difference between the two UNIX timestamps.
Example: in the php script, the birth date from html form submission is received to calculate the user's age.

 

Date and time formatting output
When the date and time need to be saved or calculated, the UNIX timestamp is used as the standard format.
Disadvantage: poor readability of unix timestamp format
Solution: Call date () to format the local time and date
Syntax date (format, timestamp) format a local time and date

 

---------------------------------

Notes:

References: PHP

Unix timestamp: the number of seconds that have elapsed since, January 1, January 1, 1970. 1. convert the date to UNIX timestamp mktime (): it can be automatically corrected...

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.