Tonight I feel close to PHP strtotime functions

Source: Internet
Author: User

First look at the manual introduction:
strtotime-to parse the datetime description of any English text into a Unix timestamp
Format: int strtotime (string $time [, int $now])
This function expects to accept a string containing the U.S. English date format and attempt to resolve it to a Unix timestamp (the number of seconds from January 1 1970 00:00:00 GMT) whose value is relative to the time given by the now parameter, if this parameter is not provided, the current time of the system.
This function uses the TZ environment variable, if any, to calculate the timestamp. Since PHP 5.1.0 There is an easier way to define a time zone for all date/time functions. This procedure is described in the Date_default_timezone_get () function page.
Note: If the given year is a two-digit format, its value of 0-69 means that 2000-2069,70-100 represents 1970-2000.
Parameters
Time
The parsed string, formatted according to the syntax of the gnu» date input format. Before PHP 5.0, there were no milliseconds allowed in time, but could be omitted from PHP 5.0.
Now
The timestamp used to calculate the return value. The default value of this parameter is time () of the current time, or it can be set to a timestamp of another time (I have been ignoring a feature ah, ashamed)
Return value: Success returns an inter-stamp, otherwise FALSE is returned. Before PHP 5.1.0, this function returns 1 on failure, and later returns false.
The first parameter of Strtotime can be our common English time format, such as "2008-8-20" or "Ten September 2000" and so on. It can also be a time description based on the parameter now, such as "+1 Day" and so on.
The following is the list of available parameters for the latter, where "current time" refers to the value of the second parameter now, which defaults to the current time of the Strtotime
1. Month, day English name and its common abbreviations list:
January,february,march,april,may,june,july,august,september,sept,october,november,december,
Sunday,monday,tuesday,tues,wednesday,wednes,thursday,thur,thurs,friday,saturday
2. Time parameter Hexiang Description:
Am:the time is before noon AM
Pm:the time is noon or later PM
Year:one year; For example, the next year, such as next year, represents the next
Month:one month; For example, ' last month ', for example, the previous moon
Fortnight:two weeks; For example, "a fortnight ago" two weeks, for example "a fortnight ago" represents two weeks ago
Week:one Week Week
Day:a Day
Hour:an Hour Hours
Minute:a minute min
Min:same as minute with "minute"
Second:a Second sec
Sec:same as second with "second"
3. Correlation and Sequence Description:
+n/-n: In the current time, add a minus the specified time, such as "+1 hour" refers to the current time plus an hour
Ago:time relative to now; such as "hours ago" with current time, such as "hours ago" stands for "24 hours ago"
Tomorrow:24 hours later than the current date and time is the same as the present (including date and time), tomorrow
Yesterday:24 hours earlier than the current date and time is the same as the date and time.
Today:the Current date and time (including date and time)
Now:the Current date and time (including date and time)
Last:modifier meaning "the preceding"; For example, "Last Tuesday" stands for "previous", for example "last Tuesday" represents "the same time on Tuesday"
This:the given time during the current day or the next occurrence of the given time; For example, ' This 7am ' gives the timestamp for the ' the ', ' the ' This week ' gives the timestamp for one we The time stamp of the specified time of the day of the current time or the following period, such as "This 7am" gives the time stamp of the day 7:00, and "This week" gives the timestamp of the whole week starting from the present time, This is the current time (tested by myself: Strtotime (' this Week ') =strtotime (' Now '));
Next:modifier meaning the current time value of the subject plus one; For example, the current time of "next hour" plus the specified time, such as "next hour" means the current time plus an hour, plus 3600
Come here first, there is no time to translate the following
First:ordinal modifier, esp. for months; For example, "may first" (Actually, it ' s just, the same as next)
Third:see First (note that there was no "second" for ordinality, since-would conflict with the second time value)
Fourth:see First
Fifth:see First
Sixth:see First
Seventh:see First
Eighth:see First
Ninth:see First
Tenth:see First
Eleventh:see First
Twelfth:see First
4. Time Zone Description:
Gmt:greenwich Mean Time
ut:coordinated Universal Time
Utc:same as UT
Wet:western European Time
Bst:british Summer Time
Wat:west Africa Time
At:azores time
Ast:atlantic Standard Time
Adt:atlantic Daylight Time
Est:eastern Standard Time
Edt:eastern Daylight Time
Cst:central Standard Time
Cdt:central Daylight Time
Mst:mountain Standard Time
Mdt:mountain Daylight Time
Pst:pacific Standard Time
Pdt:pacific Daylight Time
Yst:yukon Standard Time
Ydt:yukon Daylight Time
Hst:hawaii Standard Time
Hdt:hawaii Daylight Time
Cat:central Alaska Time
Akst:alaska Standard Time
Akdt:alaska Daylight Time
Ahst:alaska-hawaii Standard Time
Nt:nome time
Idlw:international Date Line West
Cet:central European Time
Met:middle European Time
Mewt:middle European Winter Time
Mest:middle European Summer Time
Mesz:middle European Summer Time
Swt:swedish Winter Time
Sst:swedish Summer Time
Fwt:french Winter Time
Fst:french Summer Time
Eet:eastern Europe time, USSR Zone 1
Bt:baghdad time, USSR Zone 2
ZP4:USSR Zone 3
ZP5:USSR Zone 4
ZP6:USSR Zone 5
Wast:west Australian Standard Time
Wadt:west Australian Daylight Time
Cct:china Coast time, USSR Zone 7
Jst:japan Standard Time, USSR Zone 8
East:eastern Australian Standard Time
Eadt:eastern Australian Daylight Time
Gst:guam Standard Time, USSR Zone 9
Nzt:new Zealand Time
Nzst:new Zealand Standard Time
Nzdt:new Zealand Daylight Time
Idle:international Date Line East
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.

The above describes the tonight I feel close to you PHP strtotime functions in detail, including The tonight I feel close to you, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.

    Tags Index: