You may have some knowledge of the PHP timestamp , so how do we apply it to get a specific date? Today we're going to introduce you to the specifics of how php timestamp gets the current period.
Implementation function: Gets the timestamp of a date, or gets the php timestamp for a certain time.
Strtotime can parse the date-time description of any English text into a Unix timestamp , we use the mktime () or date () format date time to get the specified timestamp to achieve the required DateTime.
strtotime resolves a date-time description of any English text to a UNIX timestamp [converts system time to UNIX timestamp]
First, get the Unix timestamp strtotime ("2009-1-22〃" example) for the specified date as follows:
Echo strtotime ("2009-1-22") Results: 1232553600
Note: Return January 22, 2009 0:0 0 seconds time stamp
Second, obtain the English text date time example as follows:
Easy to compare, using date to convert the timestamp to the system time with the specified timestamp
(1) Print tomorrow at this time the timestamp strtotime ("+1 Day")
Current time : Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("+1 Day") Results: 2009-01-23 09:40:25
(2) Print yesterday at this time PHP timestamp strtotime ("-1 day")
Current time : Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("1 day")) Results: 2009-01-21 09:40:25
(3) Print the timestamp strtotime ("+1 Week") at this time next week
Current time : Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("+1 Week") Results: 2009-01-29 09:40:25
(4) Print the timestamp strtotime ("-1 week") at this time last week
Current time : Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("1 week")) Results: 2009-01-15 09:40:25
(5) Print the php timestamp strtotime specified next week ("next Thursday")
Current time : Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("next Thursday") Results: 2009-01-29 00:00:00
(6) Print a timestamp strtotime (" last Thursday") that specifies the previous week
Current time : Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("last Thursday") Results: 2009-01-15 00:00:00
The above example shows that Strtotime can parse the date-time description of any English text into a Unix timestamp , and we get the specified PHP timestamp in conjunction with the Mktime () or date () format date time . The date time required for the implementation.