Usage of strtotime () function in php

Source: Internet
Author: User
Tags current time datetime echo date

1. Obtain the unix timestamp of the specified date
Strtotime ("2009-1-22") example:
1. echo strtotime ("2009-1-22 ")

Result: 1232553600
Returns the January 22, 2009 00:00:00 timestamp.
2. Obtain the date and time of the English text
Example:
For ease of comparison, date is used to convert a timestamp from a specified timestamp to a system time
(1) print the timestamp strtotime ("+ 1 day") at this time tomorrow ")
Current time:
1. echo date ("Y-m-d H: I: s", time ())

Result: 09:40:25
Specified Time:
1. echo date ("Y-m-d H: I: s", strtotime ("+ 1 day "))

Result: 09:40:25
(2) print the timestamp strtotime ("-1 day") at this time yesterday ")
Current time:
1. echo date ("Y-m-d H: I: s", time ())

Result: 09:40:25
Specified Time:
1. echo date ("Y-m-d H: I: s", strtotime ("-1 day "))

Result: 09:40:25
(3) print the timestamp strtotime ("+ 1 week") for the next week ")
Current time:
1. echo date ("Y-m-d H: I: s", time ())

Result: 09:40:25
Specified Time:
1. echo date ("Y-m-d H: I: s", strtotime ("+ 1 week "))

Result: 09:40:25
(4) print the timestamp strtotime ("-1 week") of the last week ")
Current time:
1. echo date ("Y-m-d H: I: s", time ())

Result: 09:40:25
Specified Time:
1. echo date ("Y-m-d H: I: s", strtotime ("-1 week "))

Result: 09:40:25
(5) print the specified timestamp strtotime for the next week ("next Thursday ")
Current time:
1. echo date ("Y-m-d H: I: s", time ())

Result: 09:40:25
Specified Time:
1. echo date ("Y-m-d H: I: s", strtotime ("next Thursday "))

Result: 00:00:00
(6) print the timestamp strtotime of the specified last week ("last Thursday ")
Current time:
1. echo date ("Y-m-d H: I: s", time ())

Result: 09:40:25
Specified Time:
1. echo date ("Y-m-d H: I: s", strtotime ("last Thursday "))

Result: 00:00:00
The preceding example shows that strtotime can parse the datetime description of any English text into a Unix timestamp. We can use mktime () or date () to format the datetime to get the specified timestamp, the date and time required for implementation.

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.