There is a function called Strtotime in PHP. Strtotime implementation: Gets the timestamp of a date, or gets the timestamp of a time. Strtotime to parse the datetime description of any English text into a UNIX timestamp [convert system time to UNIX timestamp]
One, gets the UNIX timestamp for the specified date
Strtotime ("2009-1-22") examples are as follows:
1.echo strtotime ("2009-1-22")
Results: 1232553600
Description: Return January 22, 2009 0:0 0 seconds timestamp
Second, get the English text date time
Examples are as follows:
Easy to compare, use date to convert time stamp to system time with specified timestamp
(1) Print the timestamp for tomorrow at this time Strtotime ("+1 Day")
Current time:
1.echo date ("Y-m-d h:i:s", Time ())
Result: 2009-01-22 09:40:25
Specify time:
1.echo date ("Y-m-d h:i:s", Strtotime ("+1 Day")
Result: 2009-01-23 09:40:25
(2) Print the timestamp at this time yesterday Strtotime ("-1 day")
Current time:
1.echo date ("Y-m-d h:i:s", Time ())
Result: 2009-01-22 09:40:25
Specify time:
1.echo date ("Y-m-d h:i:s", Strtotime ("1 day"))
Result: 2009-01-21 09:40:25
(3) Print timestamp strtotime ("+1 Week") at this time next week
Current time:
1.echo date ("Y-m-d h:i:s", Time ())
Result: 2009-01-22 09:40:25
Specify time:
1.echo date ("Y-m-d h:i:s", Strtotime ("+1 Week"))
Result: 2009-01-29 09:40:25
(4) Print timestamp strtotime ("1 week") at this time last week
Current time:
1.echo date ("Y-m-d h:i:s", Time ())
Result: 2009-01-22 09:40:25
Specify time:
1.echo date ("Y-m-d h:i:s", Strtotime ("1 week"))
Result: 2009-01-15 09:40:25
(5) Print the time stamp specified next week strtotime ("next Thursday")
Current time:
1.echo date ("Y-m-d h:i:s", Time ())
Result: 2009-01-22 09:40:25
Specify time:
1.echo date ("Y-m-d h:i:s", Strtotime ("next Thursday"))
Result: 2009-01-29 00:00:00
(6) Print the timestamp strtotime ("last Thursday") specified on the previous day of the week
Current time:
1.echo date ("Y-m-d h:i:s", Time ())
Result: 2009-01-22 09:40:25
Specify time:
1.echo date ("Y-m-d h:i:s", Strtotime ("last Thursday"))
Result: 2009-01-15 00:00:00
The above example shows that Strtotime can parse the datetime description of any English text into a Unix timestamp, and we get the specified timestamp by combining mktime () or date () format date time to achieve the required date time.
Hopefully, after the introduction of this article, you can already master the Strtotime function usage.
http://www.bkjia.com/PHPjc/324742.html www.bkjia.com true http://www.bkjia.com/PHPjc/324742.html techarticle there is a function called Strtotime in PHP. Strtotime implementation: Gets the timestamp of a date, or gets the timestamp of a time. Strtotime the date and time of any English text ...