Home > Backend Development > PHP Tutorial > tonight i feel close to you PHP strtotime function detailed explanation

tonight i feel close to you PHP strtotime function detailed explanation

WBOY
Release: 2016-07-29 08:41:33
Original
947 people have browsed it

First read the manual introduction:
strtotime - Parse the date and time description of any English text into a Unix timestamp
Format: int strtotime ( string $time [, int $now ] )
 This function is expected to accept a character containing the US English date format The concatenation attempts to parse this into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT) relative to the time given by the now parameter, or the current system time if this parameter is not provided.
 This function will use the TZ environment variable (if any) to calculate the timestamp. Since PHP 5.1.0 there is an easier way to define the time zone used in all date/time functions. This process is documented on the date_default_timezone_get() function page.
Note: If the given year is in two-digit format, its value 0-69 means 2000-2069, and 70-100 means 1970-2000.
Parameter
time
The parsed string, formatted according to the syntax of GNU » Date Input Format. Before PHP 5.0, milliseconds were not allowed in time. Since PHP 5.0, they are allowed but will be ignored.
now
Used to calculate the timestamp of the return value. The default value of this parameter is the current time time(), and can also be set to a timestamp of other times (a feature I have always ignored, I am ashamed)
Return value: Returns the timestamp if successful, otherwise returns FALSE. Before PHP 5.1.0, this function returned -1 on failure, and later versions returned false.
 The first parameter of strtotime can be our common English time format, such as "2008-8-20" or "10 September 2000" etc. It can also be a time description based on the parameter now, such as "+1 day" and so on.
The following is a list of available parameters for the latter method, where "current time" refers to the value of the second parameter now of strtotime, and the default is the current time
1. List of month, Japanese and English names and their common abbreviations:
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 Parameters and detailed descriptions:
am : the time is before noon
pm : the time is noon or later
year: one year; for example, “next year” represents next year
month: one month; for example, “last month” month, such as “last month” represents the previous month
fortnight: two weeks; for example, “a fortnight ago” Two weeks, such as “a fortnight ago” represents two weeks ago
week : one week
day: a day
hour: an hour hour
minute : a minute
min : same as minute
second : a second sec : same as second
3 .Related and sequence instructions:
+n/-n: Calculate the current time, plus or minus the specified time. For example, “+1 hour” means the current time plus one hour.
ago: time relative to now; such as “24 "hours ago" Count forward based on the current time, for example, "24 hours ago" means "24 hours ago"
tomorrow: 24 hours later than the current date and time Based on the current time (including date and time), the same time tomorrow
yesterday : 24 hours earlier than the current date and time Based on the current time (including date and time), the same time yesterday
today : the current date and time Current time (including date and time)
now : the current date and time Current time (including date and time)
last : modifier meaning “the preceding”; for example, “last tuesday” represents “the previous one”, such as “last tuesday” represents “the same time last 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 07:00 on the current day, while “this week” gives the timestamp for one week from the current time specification of the day Time or a timestamp of the following time period, for example, "this 7am" gives a timestamp of 7:00 that day, and "this week" gives a timestamp of a whole week starting from the current time, which is the current time (Tested by me: strtotime('this week')=strtotime('now'));
next : modifier meaning the current time value of the subject plus one; for example, “next hour” current time plus the specified time , for example, "next hour" refers to the current time plus one hour, that is, 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 is no “second” for ordinaryity, since that 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 function: get the timestamp of a certain date, or get the timestamp of a certain time.strtotime parses the date and time description of any English text into a Unix timestamp [converts the system time into a unix timestamp]
1. Get the unix timestamp of the specified date
strtotime("2009-1-22") The example is as follows:
1 .echo strtotime("2009-1-22")
Result: 1232553600
Description: Return the timestamp of 0:00:00 on January 22, 2009
Second, get the English text date and time
The example is as follows:
Easy to compare, Use date to convert the current timestamp and the specified timestamp into system time
(1) Print the timestamp at this time tomorrow strtotime("+1 day")
Current time:
1.echo date("Y-m-d H:i:s ",time())
Result: 2009-01-22 09:40:25
Specified time:
1.echo date("Y-m-d H:i:s",strtotime("+1 day"))
Result: 2009-01-23 09:40:25
(2) Print the timestamp of yesterday 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
Specified time:
1.echo date("Y-m-d H:i:s",strtotime("-1 day"))
Result: 2009-01- 21 09:40:25
(3) Print the timestamp at this time next week strtotime("+1 week")
Current time:
1.echo date("Y-m-d H:i:s",time())
Result: 2009-01-22 09:40:25
Specified time:
1.echo date("Y-m-d H:i:s",strtotime("+1 week"))
Result: 2009-01-29 09 :40:25
(4) Print the timestamp at this time last week strtotime("-1 week")
Current time:
1.echo date("Y-m-d H:i:s",time())
Result :2009-01-22 09:40:25
Specified time:
1.echo date("Y-m-d H:i:s",strtotime("-1 week"))
Result: 2009-01-15 09:40 :25
(5) Print the timestamp of the specified next day of the week strtotime("next Thursday")
Current time:
1.echo date("Y-m-d H:i:s",time())
Result: 2009-01 -22 09:40:25
Specified time:
1.echo date("Y-m-d H:i:s",strtotime("next Thursday"))
Result: 2009-01-29 00:00:00
(6 )Print the timestamp of the specified day of the week strtotime("last Thursday")
Current time:
1.echo date("Y-m-d H:i:s",time())
Result: 2009-01-22 09:40 :25
Specified time:
1.echo date("Y-m-d H:i:s",strtotime("last Thursday"))
Result: 2009-01-15 00:00:00
As can be seen from the above example, strtotime can The date and time description of any English text is parsed into a Unix timestamp. We combine mktime() or date() to format the date and time to obtain the specified timestamp and achieve the required date and time.
I hope that after the introduction of this article, you can master the usage of strtotime function.

The above introduces the detailed explanation of tonight i feel close to you PHP strtotime function, including the content of tonight i feel close to you. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template