This article introduces the use of the time function strtotime in PHP, introduces some specific examples to help everyone understand, there is a need for friends to refer to the next. The function of the Strtotime function in PHP: Gets the timestamp of a date, or gets the timestamp of a time. strtotime resolves the datetime description of any English text to a UNIX timestamp [translates the system time into a UNIX timestamp]. One, gets the UNIX timestamp for the specified date Strtotime ("2009-1-22")Example: Echo strtotime ("2009-1-22")Results: 1232553600 Description: Return January 22, 2009 0:0 0 seconds timestamp Second, get the English text date time use date to convert the timestamp with the specified timestamp to the system time (1) Print tomorrow at this time timestamp strtotime ("+1 Day") Current time: echo Date ("Y-m-d h:i:s", Time ())Result: 2009-01-22 09:40:25 Specify time: 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: echo Date ("Y-m-d h:i:s", Time ())Result: 2009-01-22 09:40:25 Specify time: 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: echo Date ("Y-m-d h:i:s", Time ())Result: 2009-01-22 09:40:25 Specify time: 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: echo Date ("Y-m-d h:i:s", Time ())Result: 2009-01-22 09:40:25 Specify time: 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: echo Date ("Y-m-d h:i:s", Time ())Result: 2009-01-22 09:40:25 Specify time: 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") Current time of week: echo Date ("Y-m-d h:i:s", Time ())Result: 2009-01-22 09:40:25 Specify time: echo Date ("Y-m-d h:i:s", Strtotime ("last Thursday"))Result: 2009-01-15 00:00:00 From the above example, we can see that the Strtotime () function can parse the datetime description of any English text into a Unix timestamp, and if it is combined with the mktime () or date () format datetime to obtain the specified timestamp, the required datetime is achieved. It is recommended that you do a hands-on test of the above example, more hands-on, write code, practice makes perfect. |