Definitions and usage
The strftime () function formats the local time/date according to the locale setting.
Grammar
Strftime (format,timestamp) parameter description
Format is optional. Specify how the results are returned.
Timestamp optional.
Tips and comments
Hint: the same behavior as Gmstrftime (), and the difference is that the return time is local time.
Example
Output strftime () and Gmstrftime () results:
<?php Tutorial
Echo (Strftime ("%b%d%Y%x", Mktime (20,0,0,12,31,98)));
Echo (Gmstrftime ("%b%d%Y%x", Mktime (20,0,0,12,31,98)));
Output current date, time, and time zone
Echo (Gmstrftime ("It is%a on%b%d,%Y,%x time zone:%Z", Time ()));
?> output:
Dec 31 1998 20:00:00
Dec 31 1998 19:00:00
It is Wed in 2006, 11:32:10 time zone:w. Europe Standard Time
format Description Example returned values
Day------
%a an abbreviated textual representation of the Day Sun through Sat
%A A Full textual representation of the ' Day Sunday through Saturday
%d Two-digit day of the Month (with leading zeros)-
%e Day of the month, with a spaces preceding single digits 1 to
%j Day of The year, 3 digits with leading zeros 001 to 366
%u ISO-8601 numeric representation of the ' Day of the ' Week 1 (for Mon Day) Though 7 [for Sunday]
%w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) br> Week------
%u Week number of the given year, starting with the ' the ' the ' 13th Full week of the year
%V iso-8601:1988 Week number of the given year, starting with the At least 4 weekdays with
Monday being the start of the week through (where accounts for a overlapping week)
K
The year beginning with a Monday)
Month------
%b abbreviated month name based on the locale
%B full month name, based on the locale January through December
%h abbreviated month name, based on the locale (an alias of%b) after the through DEC
%m two digit representation of the month (for January) through
Year------
%c two digit representation of the century (year divided by-, truncated to a integer) for the 20th century
%g two digit representation of the year going by iso-8601:1988 standards (=%V) example:09 for the week of January 6, 2 009
%G the full four-digit version of%G example:2008 for the week of January 3, 2009
%y two digit representation of the year example:09 for 2009, 1979
%Y Four digit Representation for the year example:2038
Time------
%H two digit representation of the hour in 24-hour format through 23
%I Two digit representation of the hour in 12-hour format through 12
%l (lower-case ' l ') Hour in 12-hour format, with a spaces preceeding single digits 1 through 12
%m two digit representation minute 59
%p upper-case ' AM ' or ' PM ' based on the given time example:am for 00:31, PM for 22:23
%P lower-case ' am ' or ' PM ' based on the given time example:am for 00:31, PM for 22:23
%r Same as "%i:%m:%s%p" example:09:34:17 PM for 21:34:17
%R Same as "%h:%m" example:00:35 for 12:35 AM, 16:44 for 4:44 PM
%s Two digit representation second through 59
%T Same as "%h:%m:%s" Example:21:34:17 for 09:34:17 PM
%x preferred time representation based on locale, without the date example:03:59:16 or 15:59:16
%z either the time zone offset to UTC or abbreviation (depends on operating system) Example: -0500 or EST for Easter N
Time
%Z The time zone offset/abbreviation option isn't given by%Z (depends on operating system) Example: -0500 or EST for Easter N
Time
Time and Date Stamps Tutorial------
%c preferred date and time stamp based on the local example:tue Feb 5 00:45:10 2009 for February 4, 2009 at 12:45:10 AM
%d Same as "%m/%d/%y" example:02/05/09 for February 5, 2009
%F Same as "%y-%m-%d" (commonly used in database Datestamps) example:2009-02-05 for February 5, 2009
%s Unix Epoch time timestamp (same as the time () function) example:305815200 for September, 1979 08:40:00 AM
%x preferred date representation based on locale, without the time example:02/05/09 for February 5, 2009
Miscellaneous------
%n A newline character ("")---
%t A Tab character ("")---
% literal percentage character ("%")---
<?php
/* December 2002/january 2003
Isowk M Tu W Thu F Sa Su
----- ----------------------------
51 16 17 18 19 20 21 22
52 23 24 25 26 27 28 29
1 30 31 1 2 3 4 5
2 6 7 8 9 10 11 12
3 13 14 15 16 17 18 19 * *
outputs:12/28/2002-%v,%g,%y = 52,2002,2002
echo "12/28/2002-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("12/28/2002")). " ";
outputs:12/30/2002-%v,%g,%y = 1,2003,2002
echo "12/30/2002-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("12/30/2002")). " ";
outputs:1/3/2003-%v,%g,%y = 1,2003,2003
echo "1/3/2003-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("1/3/2003")). " ";
outputs:1/10/2003-%v,%g,%y = 2,2003,2003
echo "1/10/2003-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("1/10/2003")). " ";
/* December 2004/january 2005
Isowk M Tu W Thu F Sa Su
----- ----------------------------
51 13 14 15 16 17 18 19
52 20 21 22 23 24 25 26
53 27 28 29 30 31 1 2
1 3 4 5 6 7 8 9
2 10 11 12 13 14 15 16 * *
outputs:12/23/2004-%v,%g,%y = 52,2004,2004
echo "12/23/2004-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("12/23/2004")). " ";
outputs:12/31/2004-%v,%g,%y = 53,2004,2004
echo "12/31/2004-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("12/31/2004")). " ";
outputs:1/2/2005-%v,%g,%y = 53,2004,2005
echo "1/2/2005-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("1/2/2005")). " ";
outputs:1/3/2005-%v,%g,%y = 1,2005,2005
echo "1/3/2005-%v,%g,%y =". Strftime ("%v,%g,%y", Strtotime ("1/3/2005")). " ";
?>
]
Gets the Unix timestamp strtotime ("2009-1-22") of 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 the timestamp strtotime ("-1 day") at this time yesterday
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 a timestamp strtotime ("next Thursday") that specifies the next day of the 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 ("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