php-doc-en/functions/datetime.xml
Hartmut Holzgraefe 7839d91186 added DO NOT EDIT noctice to old english functions files,
removing the others


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@78562 c90b9560-bf6c-de11-be94-00142212c4b1
2002-04-17 19:58:46 +00:00

1184 lines
35 KiB
XML

<!-- D O N O T E D I T T H I S F I L E ! ! !
it is still here for historical reasons only
(as translators may need to check old revision diffs)
if you want to change things documented in this file
you should now edit the files found under en/reference
instead -->
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.72 $ -->
<reference id="ref.datetime">
<title>Date and Time functions</title>
<titleabbrev>Date/time</titleabbrev>
<refentry id="function.checkdate">
<refnamediv>
<refname>checkdate</refname>
<refpurpose>Validate a gregorian date/time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>checkdate</methodname>
<methodparam><type>int</type><parameter>month</parameter></methodparam>
<methodparam><type>int</type><parameter>day</parameter></methodparam>
<methodparam><type>int</type><parameter>year</parameter></methodparam>
</methodsynopsis>
<para>
Returns &true; if the date given is valid; otherwise returns &false;.
Checks the validity of the date formed by the arguments. A date
is considered valid if:
<itemizedlist>
<listitem>
<simpara>
year is between 1 and 32767 inclusive
</simpara>
</listitem>
<listitem>
<simpara>
month is between 1 and 12 inclusive
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>Day</parameter> is within the allowed number of
days for the given <parameter>month</parameter>. Leap
<parameter>year</parameter>s are taken into consideration.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
See also <function>mktime</function> and <function>strtotime</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.date">
<refnamediv>
<refname>date</refname>
<refpurpose>Format a local time/date</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>date</methodname>
<methodparam><type>string</type><parameter>format</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
timestamp
</parameter></methodparam>
</methodsynopsis>
<para>
Returns a string formatted according to the given format string using the
given integer <parameter>timestamp</parameter> or the current local time
if no timestamp is given.
<note>
<para>
The valid range of a timestamp is typically from Fri, 13 Dec
1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are
the dates that correspond to the minimum and maximum values for
a 32-bit signed integer.)
</para>
<para>
To generate a timestamp from a string representation of the date, you
may be able to use <function>strtotime</function>. Additionally, some
databases have functions to convert their date formats into timestamps
(such as MySQL's UNIX_TIMESTAMP function).
</para>
</note>
</para>
<para>
The following characters are recognized in the format string:
<itemizedlist>
<listitem>
<simpara>
a - "am" or "pm"
</simpara>
</listitem>
<listitem>
<simpara>
A - "AM" or "PM"
</simpara>
</listitem>
<listitem>
<simpara>
B - Swatch Internet time
</simpara>
</listitem>
<listitem>
<simpara>
d - day of the month, 2 digits with leading zeros; i.e. "01"
to "31"
</simpara>
</listitem>
<listitem>
<simpara>
D - day of the week, textual, 3 letters; i.e. "Fri"
</simpara>
</listitem>
<listitem>
<simpara>
F - month, textual, long; i.e. "January"
</simpara>
</listitem>
<listitem>
<simpara>
g - hour, 12-hour format without leading zeros; i.e. "1" to
"12"
</simpara>
</listitem>
<listitem>
<simpara>
G - hour, 24-hour format without leading zeros; i.e. "0" to
"23"
</simpara>
</listitem>
<listitem>
<simpara>
h - hour, 12-hour format; i.e. "01" to "12"
</simpara>
</listitem>
<listitem>
<simpara>
H - hour, 24-hour format; i.e. "00" to "23"
</simpara>
</listitem>
<listitem>
<simpara>
i - minutes; i.e. "00" to "59"
</simpara>
</listitem>
<listitem>
<simpara>
I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
</simpara>
</listitem>
<listitem>
<simpara>
j - day of the month without leading zeros; i.e. "1" to "31"
</simpara>
</listitem>
<listitem>
<simpara>
l (lowercase 'L') - day of the week, textual, long;
i.e. "Friday"
</simpara>
</listitem>
<listitem>
<simpara>
L - boolean for whether it is a leap year; i.e. "0" or "1"
</simpara>
</listitem>
<listitem>
<simpara>
m - month; i.e. "01" to "12"
</simpara>
</listitem>
<listitem>
<simpara>
M - month, textual, 3 letters; i.e. "Jan"
</simpara>
</listitem>
<listitem>
<simpara>
n - month without leading zeros; i.e. "1" to "12"
</simpara>
</listitem>
<listitem>
<simpara>
O - Difference to Greenwich time in hours; i.e. "+0200"
</simpara>
</listitem>
<listitem>
<simpara>
r - RFC 822 formatted date; i.e. "Thu, 21 Dec 2000 16:01:07 +0200"
(added in PHP 4.0.4)
</simpara>
</listitem>
<listitem>
<simpara>
s - seconds; i.e. "00" to "59"
</simpara>
</listitem>
<listitem>
<simpara>
S - English ordinal suffix for the day of the month, 2 characters;
i.e. "th", "nd"
</simpara>
</listitem>
<listitem>
<simpara>
t - number of days in the given month; i.e. "28" to "31"
</simpara>
</listitem>
<listitem>
<simpara>
T - Timezone setting of this machine; i.e. "MDT"
</simpara>
</listitem>
<listitem>
<simpara>
U - seconds since the epoch
</simpara>
</listitem>
<listitem>
<simpara>
w - day of the week, numeric, i.e. "0" (Sunday) to "6"
(Saturday)
</simpara>
</listitem>
<listitem>
<simpara>
W - ISO-8601 week number of year, weeks starting on monday (added in PHP 4.1.0)
(Saturday)
</simpara>
</listitem>
<listitem>
<simpara>
Y - year, 4 digits; i.e. "1999"
</simpara>
</listitem>
<listitem>
<simpara>
y - year, 2 digits; i.e. "99"
</simpara>
</listitem>
<listitem>
<simpara>
z - day of the year; i.e. "0" to "365"
</simpara>
</listitem>
<listitem>
<simpara>
Z - timezone offset in seconds (i.e. "-43200" to "43200"). The
offset for timezones west of UTC is always negative, and for
those east of UTC is always positive.
</simpara>
</listitem>
</itemizedlist>
Unrecognized characters in the format string will be printed
as-is. The "Z" format will always return "0" when using
<function>gmdate</function>.
</para>
<para>
<example>
<title><function>date</function> example</title>
<programlisting role="php">
<![CDATA[
echo date ("l dS of F Y h:i:s A");
echo "July 1, 2000 is on a " . date ("l", mktime(0,0,0,7,1,2000));
]]>
</programlisting>
</example>
</para>
<para>
You can prevent a recognized character in the format string from being
expanded by escaping it with a preceding backslash. If the character with
a backslash is already a special sequence, you may need to also escape
the backslash.
<example>
<title>Escaping characters in <function>date</function></title>
<programlisting role="php">
<![CDATA[
echo date("l \\t\h\e jS"); // prints something like 'Saturday the 8th'
]]>
</programlisting>
</example>
</para>
<para>
It is possible to use <function>date</function> and
<function>mktime</function> together to find dates in the future
or the past.
<example>
<title>
<function>date</function> and <function>mktime</function>
example
</title>
<programlisting role="php">
<![CDATA[
$tomorrow = mktime (0,0,0,date("m") ,date("d")+1,date("Y"));
$lastmonth = mktime (0,0,0,date("m")-1,date("d"), date("Y"));
$nextyear = mktime (0,0,0,date("m"), date("d"), date("Y")+1);
]]>
</programlisting>
</example>
<note>
<para>
This can be more reliable than simply adding or subtracting the number
of seconds in a day or month to a timestamp because of daylight savings
time.
</para>
</note>
</para>
<para>
Some examples of <function>date</function> formatting. Note that
you should escape any other characters, as any which currently
have a special meaning will produce undesirable results, and
other characters may be assigned meaning in future PHP versions.
When escaping, be sure to use single quotes to prevent characters
like \n from becoming newlines.
<example>
<title>
<function>date</function> Formatting
</title>
<programlisting role="php">
<![CDATA[
/* Today is March 10th, 2001, 5:16:18 pm */
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month
$today = date("H:i:s"); // 17:16:17
]]>
</programlisting>
</example>
</para>
<para>
To format dates in other languages, you should use the
<function>setlocale</function> and <function>strftime</function>
functions.
</para>
<para>
See also <function>getlastmod</function>, <function>gmdate</function>,
<function>mktime</function>, <function>strftime</function>
and <function>time</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getdate">
<refnamediv>
<refname>getdate</refname>
<refpurpose>Get date/time information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>getdate</methodname>
<methodparam choice="opt"><type>int</type><parameter>timestamp</parameter></methodparam>
</methodsynopsis>
<para>
Returns an associative array containing the date information of
the <parameter>timestamp</parameter>, or the current local time if
no timestamp is given, as the following array
elements:
<itemizedlist>
<listitem>
<simpara>
"seconds" - seconds
</simpara>
</listitem>
<listitem>
<simpara>
"minutes" - minutes
</simpara>
</listitem>
<listitem>
<simpara>
"hours" - hours
</simpara>
</listitem>
<listitem>
<simpara>
"mday" - day of the month
</simpara>
</listitem>
<listitem>
<simpara>
"wday" - day of the week, numeric : from 0 as Sunday up to 6 as Saturday
</simpara>
</listitem>
<listitem>
<simpara>
"mon" - month, numeric
</simpara>
</listitem>
<listitem>
<simpara>
"year" - year, numeric
</simpara>
</listitem>
<listitem>
<simpara>
"yday" - day of the year, numeric; i.e. "299"
</simpara>
</listitem>
<listitem>
<simpara>
"weekday" - day of the week, textual, full; i.e. "Friday"
</simpara>
</listitem>
<listitem>
<simpara>
"month" - month, textual, full; i.e. "January"
</simpara>
</listitem>
</itemizedlist>
<example>
<title>
<function>getdate</function> example
</title>
<programlisting role="php">
<![CDATA[
$today = getdate();
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];
echo "$month $mday, $year";
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.gettimeofday">
<refnamediv>
<refname>gettimeofday</refname>
<refpurpose>Get current time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>gettimeofday</methodname>
<void/>
</methodsynopsis>
<para>
This is an interface to gettimeofday(2). It returns an
associative array containing the data returned from the system
call.
<itemizedlist>
<listitem>
<simpara>
"sec" - seconds
</simpara>
</listitem>
<listitem>
<simpara>
"usec" - microseconds
</simpara>
</listitem>
<listitem>
<simpara>
"minuteswest" - minutes west of Greenwich
</simpara>
</listitem>
<listitem>
<simpara>
"dsttime" - type of dst correction
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.gmdate">
<refnamediv>
<refname>gmdate</refname>
<refpurpose>Format a GMT/CUT date/time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>gmdate</methodname>
<methodparam><type>string</type><parameter>format</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>timestamp</parameter></methodparam>
</methodsynopsis>
<para>
Identical to the <function>date</function> function except that
the time returned is Greenwich Mean Time (GMT). For example, when
run in Finland (GMT +0200), the first line below prints "Jan 01
1998 00:00:00", while the second prints "Dec 31 1997 22:00:00".
<example>
<title><function>gmdate</function> example</title>
<programlisting role="php">
<![CDATA[
echo date ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
echo gmdate ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
]]>
</programlisting>
</example>
</para>
<para>
See also <function>date</function>, <function>mktime</function>,
<function>gmmktime</function> and <function>strftime</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gmmktime">
<refnamediv>
<refname>gmmktime</refname>
<refpurpose>Get UNIX timestamp for a GMT date</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>gmmktime</methodname>
<methodparam><type>int</type><parameter>hour</parameter></methodparam>
<methodparam><type>int</type><parameter>minute</parameter></methodparam>
<methodparam><type>int</type><parameter>second</parameter></methodparam>
<methodparam><type>int</type><parameter>month</parameter></methodparam>
<methodparam><type>int</type><parameter>day</parameter></methodparam>
<methodparam><type>int</type><parameter>year</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>is_dst</parameter></methodparam>
</methodsynopsis>
<para>
Identical to <function>mktime</function> except the passed
parameters represents a GMT date.
</para>
</refsect1>
</refentry>
<refentry id="function.gmstrftime">
<refnamediv>
<refname>gmstrftime</refname>
<refpurpose>
Format a GMT/CUT time/date according to locale settings
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>gmstrftime</methodname>
<methodparam><type>string</type><parameter>format</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>timestamp</parameter></methodparam>
</methodsynopsis>
<para>
Behaves the same as <function>strftime</function> except that the
time returned is Greenwich Mean Time (GMT). For example, when run
in Eastern Standard Time (GMT -0500), the first line below prints
"Dec 31 1998 20:00:00", while the second prints "Jan 01 1999
01:00:00".
<example>
<title><function>gmstrftime</function> example</title>
<programlisting role="php">
<![CDATA[
setlocale ('LC_TIME', 'en_US');
echo strftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n";
echo gmstrftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n";
]]>
</programlisting>
</example>
</para>
<para>
See also <function>strftime</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.localtime">
<refnamediv>
<refname>localtime</refname>
<refpurpose>Get the local time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>localtime</methodname>
<methodparam choice="opt"><type>int</type><parameter>
timestamp
</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>
is_associative
</parameter></methodparam>
</methodsynopsis>
<para>
The <function>localtime</function> function returns an array
identical to that of the structure returned by the C function
call. The first argument to <function>localtime</function> is
the timestamp, if this is not given the current time is used.
The second argument to the <function>localtime</function> is the
<parameter>is_associative</parameter>, if this is set to 0 or not
supplied than the array is returned as a regular, numerically
indexed array. If the argument is set to 1 then
<function>localtime</function> is an associative array containing
all the different elements of the structure returned by the C
function call to localtime. The names of the different keys of
the associative array are as follows:
<itemizedlist>
<listitem>
<simpara>
"tm_sec" - seconds
</simpara>
</listitem>
<listitem>
<simpara>
"tm_min" - minutes
</simpara>
</listitem>
<listitem>
<simpara>
"tm_hour" - hour
</simpara>
</listitem>
<listitem>
<simpara>
"tm_mday" - day of the month
</simpara>
</listitem>
<listitem>
<simpara>
"tm_mon" - month of the year, starting with 0 for January
</simpara>
</listitem>
<listitem>
<simpara>
"tm_year" - Years since 1900
</simpara>
</listitem>
<listitem>
<simpara>
"tm_wday" - Day of the week
</simpara>
</listitem>
<listitem>
<simpara>
"tm_yday" - Day of the year
</simpara>
</listitem>
<listitem>
<simpara>
"tm_isdst" - Is daylight savings time in effect
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.microtime">
<refnamediv>
<refname>microtime</refname>
<refpurpose>
Return current UNIX timestamp with microseconds</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>microtime</methodname>
<void/>
</methodsynopsis>
<para>
Returns the string "msec sec" where sec is the current time
measured in the number of seconds since the Unix Epoch (0:00:00
January 1, 1970 GMT), and msec is the microseconds part. This
function is only available on operating systems that support the
gettimeofday() system call.
</para>
<para>
Both portions of the string are returned in units of seconds.
<example>
<title><function>microtime</function> example</title>
<programlisting role="php">
<![CDATA[
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
for ($i=0; $i < 1000; $i++){
//do nothing, 1000 times
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Did nothing in $time seconds";
]]>
</programlisting>
</example>
</para>
<para>
See also <function>time</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mktime">
<refnamediv>
<refname>mktime</refname>
<refpurpose>Get UNIX timestamp for a date</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>mktime</methodname>
<methodparam><type>int</type><parameter>hour</parameter></methodparam>
<methodparam><type>int</type><parameter>minute</parameter></methodparam>
<methodparam><type>int</type><parameter>second</parameter></methodparam>
<methodparam><type>int</type><parameter>month</parameter></methodparam>
<methodparam><type>int</type><parameter>day</parameter></methodparam>
<methodparam><type>int</type><parameter>year</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>is_dst</parameter></methodparam>
</methodsynopsis>
<para>
<emphasis>Warning:</emphasis> Note the strange order of
arguments, which differs from the order of arguments in a regular
UNIX mktime() call and which does not lend itself well to leaving
out parameters from right to left (see below). It is a common
error to mix these values up in a script.
</para>
<para>
Returns the Unix timestamp corresponding to the arguments
given. This timestamp is a long integer containing the number of
seconds between the Unix Epoch (January 1 1970) and the time
specified.
</para>
<para>
Arguments may be left out in order from right to left; any
arguments thus omitted will be set to the current value according
to the local date and time.
</para>
<para>
<parameter>is_dst</parameter> can be set to 1 if the time is
during daylight savings time, 0 if it is not, or -1 (the default)
if it is unknown whether the time is within daylight savings time
or not. If it's unknown, PHP tries to figure it out itself. This can
cause unexpected (but not incorrect) results.
</para>
<note>
<para>
<parameter>is_dst</parameter> was added in 3.0.10.
</para>
</note>
<para>
<function>mktime</function> is useful for doing date arithmetic
and validation, as it will automatically calculate the correct
value for out-of-range input. For example, each of the following
lines produces the string "Jan-01-1998".
<example>
<title><function>mktime</function> example</title>
<programlisting role="php">
<![CDATA[
echo date ("M-d-Y", mktime (0,0,0,12,32,1997));
echo date ("M-d-Y", mktime (0,0,0,13,1,1997));
echo date ("M-d-Y", mktime (0,0,0,1,1,1998));
echo date ("M-d-Y", mktime (0,0,0,1,1,98));
]]>
</programlisting>
</example>
<parameter>Year</parameter> may be a two or four digit value,
with values between 0-69 mapping to 2000-2069 and 70-99 to
1970-1999 (on systems where time_t is a 32bit signed integer, as
most common today, the valid range for
<parameter>year</parameter> is somewhere between 1902 and 2037).
</para>
<para>
The last day of any given month can be expressed as the "0" day
of the next month, not the -1 day. Both of the following examples
will produce the string "The last day in Feb 2000 is: 29".
<example>
<title>Last day of next month</title>
<programlisting role="php">
<![CDATA[
$lastday = mktime (0,0,0,3,0,2000);
echo strftime ("Last day in Feb 2000 is: %d", $lastday);
$lastday = mktime (0,0,0,4,-31,2000);
echo strftime ("Last day in Feb 2000 is: %d", $lastday);
]]>
</programlisting>
</example>
</para>
<simpara>
Date with year, month and day equal to zero is considered illegal
(otherwise it what be regarded as 30.11.1999, which would be strange
behavior).
</simpara>
<para>
See also <function>date</function> and <function>time</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strftime">
<refnamediv>
<refname>strftime</refname>
<refpurpose>
Format a local time/date according to locale settings
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>strftime</methodname>
<methodparam><type>string</type><parameter>format</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
timestamp
</parameter></methodparam>
</methodsynopsis>
<para>
Returns a string formatted according to the given format string
using the given <parameter>timestamp</parameter> or the current
local time if no timestamp is given. Month and weekday names and
other language dependent strings respect the current locale set
with <function>setlocale</function>.
</para>
<para>
The following conversion specifiers are recognized in the format
string:
<itemizedlist>
<listitem>
<simpara>
%a - abbreviated weekday name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%A - full weekday name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%b - abbreviated month name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%B - full month name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%c - preferred date and time representation for the current
locale
</simpara>
</listitem>
<listitem>
<simpara>
%C - century number (the year divided by 100 and truncated to
an integer, range 00 to 99)
</simpara>
</listitem>
<listitem>
<simpara>
%d - day of the month as a decimal number (range 01 to 31)
</simpara>
</listitem>
<listitem>
<simpara>
%D - same as %m/%d/%y
</simpara>
</listitem>
<listitem>
<simpara>
%e - day of the month as a decimal number, a single digit is
preceded by a space (range ' 1' to '31')
</simpara>
</listitem>
<listitem>
<simpara>
%g - like %G, but without the century.
</simpara>
</listitem>
<listitem>
<simpara>
%G - The 4-digit year corresponding to the ISO week number (see %V).
This has the same format and value as %Y, except that if the ISO week
number belongs to the previous or next year, that year is used
instead.
</simpara>
</listitem>
<listitem>
<simpara>
%h - same as %b
</simpara>
</listitem>
<listitem>
<simpara>
%H - hour as a decimal number using a 24-hour clock (range 00
to 23)
</simpara>
</listitem>
<listitem>
<simpara>
%I - hour as a decimal number using a 12-hour clock (range 01
to 12)
</simpara>
</listitem>
<listitem>
<simpara>
%j - day of the year as a decimal number (range 001 to 366)
</simpara>
</listitem>
<listitem>
<simpara>
%m - month as a decimal number (range 01 to 12)
</simpara>
</listitem>
<listitem>
<simpara>
%M - minute as a decimal number
</simpara>
</listitem>
<listitem>
<simpara>
%n - newline character
</simpara>
</listitem>
<listitem>
<simpara>
%p - either `am' or `pm' according to the given time value, or
the corresponding strings for the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%r - time in a.m. and p.m. notation
</simpara>
</listitem>
<listitem>
<simpara>
%R - time in 24 hour notation
</simpara>
</listitem>
<listitem>
<simpara>
%S - second as a decimal number
</simpara>
</listitem>
<listitem>
<simpara>
%t - tab character
</simpara>
</listitem>
<listitem>
<simpara>
%T - current time, equal to %H:%M:%S
</simpara>
</listitem>
<listitem>
<simpara>
%u - weekday as a decimal number [1,7], with 1 representing
Monday
</simpara>
<warning>
<simpara>
Sun Solaris seems to start with Sunday as 1
although ISO 9889:1999 (the current C standard) clearly
specifies that it should be Monday.
</simpara>
</warning>
</listitem>
<listitem>
<simpara>
%U - week number of the current year as a decimal number,
starting with the first Sunday as the first day of the first
week
</simpara>
</listitem>
<listitem>
<simpara>
%V - The ISO 8601:1988 week number of the current year as a
decimal number, range 01 to 53, where week 1 is the first
week that has at least 4 days in the current year, and with
Monday as the first day of the week. (Use %G or %g for the year
component that corresponds to the week number for the specified
timestamp.)
</simpara>
</listitem>
<listitem>
<simpara>
%W - week number of the current year as a decimal number,
starting with the first Monday as the first day of the first
week
</simpara>
</listitem>
<listitem>
<simpara>
%w - day of the week as a decimal, Sunday being 0
</simpara>
</listitem>
<listitem>
<simpara>
%x - preferred date representation for the current locale
without the time
</simpara>
</listitem>
<listitem>
<simpara>
%X - preferred time representation for the current locale
without the date
</simpara>
</listitem>
<listitem>
<simpara>
%y - year as a decimal number without a century (range 00 to
99)
</simpara>
</listitem>
<listitem>
<simpara>
%Y - year as a decimal number including the century
</simpara>
</listitem>
<listitem>
<simpara>
%Z - time zone or name or abbreviation
</simpara>
</listitem>
<listitem>
<simpara>
%% - a literal `%' character
</simpara>
</listitem>
</itemizedlist>
<note>
<para>
Not all conversion specifiers may be supported by your C
library, in which case they will not be supported by PHP's
<function>strftime</function>. This means that %T and %D will
not work on Windows.
</para>
</note>
<example>
<title><function>strftime</function> example</title>
<programlisting role="php">
<![CDATA[
setlocale (LC_TIME, "C");
print (strftime ("%A in Finnish is "));
setlocale (LC_TIME, "fi_FI");
print (strftime ("%A, in French "));
setlocale (LC_TIME, "fr_FR");
print (strftime ("%A and in German "));
setlocale (LC_TIME, "de_DE");
print (strftime ("%A.\n"));
]]>
</programlisting>
</example>
This example works if you have the respective locales installed
in your system.
</para>
<para>
See also <function>setlocale</function> and
<function>mktime</function> and the <ulink url="&spec.strftime;">
Open Group specification of
<function>strftime</function></ulink>.
</para>
</refsect1>
</refentry>
<refentry id="function.time">
<refnamediv>
<refname>time</refname>
<refpurpose>Return current UNIX timestamp</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>time</methodname>
<void/>
</methodsynopsis>
<para>
Returns the current time measured in the number of seconds since
the Unix Epoch (January 1 1970 00:00:00 GMT).
</para>
<para>
See also <function>date</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strtotime">
<refnamediv>
<refname>strtotime</refname>
<refpurpose>
Parse about any English textual datetime description into a UNIX
timestamp
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>strtotime</methodname>
<methodparam><type>string</type><parameter>time</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>now</parameter></methodparam>
</methodsynopsis>
<simpara>
The function expects to be given a string containing an English date
format and will try to parse that format into a UNIX timestamp relative
to the timestamp given in <parameter>now</parameter>, or the current time
if none is supplied. Upon failure, <literal>-1</literal> is returned.
</simpara>
<simpara>
Because <function>strtotime</function> behaves according to GNU
date syntax, have a look at the GNU manual page titled
<ulink url="&url.gnu.man.date-input;">Date Input Formats</ulink>.
Described there is valid syntax for the <parameter>time</parameter>
parameter.
</simpara>
<para>
<example>
<title><function>strtotime</function> examples</title>
<programlisting role="php">
<![CDATA[
echo strtotime ("now"), "\n";
echo strtotime ("10 September 2000"), "\n";
echo strtotime ("+1 day"), "\n";
echo strtotime ("+1 week"), "\n";
echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime ("next Thursday"), "\n";
echo strtotime ("last Monday"), "\n";
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Checking for failure</title>
<programlisting role="php">
<![CDATA[
$str = 'Not Good';
if (($timestamp = strtotime($str)) === -1) {
echo "The string ($str) is bogus";
} else {
echo "$str == ". date('l dS of F Y h:i:s A',$timestamp);
}
]]>
</programlisting>
</example>
</para>
<note>
<para>
The valid range of a timestamp is typically from Fri, 13 Dec
1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are
the dates that correspond to the minimum and maximum values for
a 32-bit signed integer.)
</para>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->