242 lines
6.5 KiB
HTML
242 lines
6.5 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of HTTP::Date</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>HTTP::Date</H1>
|
|
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-11-23<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
HTTP::Date - HTTP::Date - date conversion routines
|
|
<A NAME="lbAC"> </A>
|
|
<H2>VERSION</H2>
|
|
|
|
|
|
|
|
version 6.05
|
|
<A NAME="lbAD"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
use HTTP::Date;
|
|
|
|
$string = time2str($time); # Format as GMT ASCII time
|
|
$time = str2time($string); # convert ASCII date to machine time
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
|
|
|
|
This module provides functions that deal the date formats used by the
|
|
<FONT SIZE="-1">HTTP</FONT> protocol (and then some more). Only the first two functions,
|
|
<B>time2str()</B> and <B>str2time()</B>, are exported by default.
|
|
<DL COMPACT>
|
|
<DT id="1">time2str( [$time] )<DD>
|
|
|
|
|
|
The <B>time2str()</B> function converts a machine time (seconds since epoch)
|
|
to a string. If the function is called without an argument or with an
|
|
undefined argument, it will use the current time.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
The string returned is in the format preferred for the <FONT SIZE="-1">HTTP</FONT> protocol.
|
|
This is a fixed length subset of the format defined by <FONT SIZE="-1">RFC 1123,</FONT>
|
|
represented in Universal Time (<FONT SIZE="-1">GMT</FONT>). An example of a time stamp
|
|
in this format is:
|
|
|
|
|
|
<P>
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
Sun, 06 Nov 1994 08:49:37 GMT
|
|
|
|
</PRE>
|
|
|
|
|
|
<DT id="2">str2time( $str [, $zone] )<DD>
|
|
|
|
|
|
|
|
|
|
The <B>str2time()</B> function converts a string to machine time. It returns
|
|
<TT>"undef"</TT> if the format of <TT>$str</TT> is unrecognized, otherwise whatever the
|
|
<TT>"Time::Local"</TT> functions can make out of the parsed time. Dates
|
|
before the system's epoch may not work on all operating systems. The
|
|
time formats recognized are the same as for <B>parse_date()</B>.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
The function also takes an optional second argument that specifies the
|
|
default time zone to use when converting the date. This parameter is
|
|
ignored if the zone is found in the date string itself. If this
|
|
parameter is missing, and the date string format does not contain any
|
|
zone specification, then the local time zone is assumed.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
If the zone is not "<TT>"GMT"</TT>`` or numerical (like ''<TT>"-0800"</TT>`` or
|
|
''<TT>+0100</TT>"), then the <TT>"Time::Zone"</TT> module must be installed in order
|
|
to get the date recognized.
|
|
<DT id="3">parse_date( $str )<DD>
|
|
|
|
|
|
|
|
|
|
This function will try to parse a date string, and then return it as a
|
|
list of numerical values followed by a (possible undefined) time zone
|
|
specifier; ($year, <TT>$month</TT>, <TT>$day</TT>, <TT>$hour</TT>, <TT>$min</TT>, <TT>$sec</TT>, <TT>$tz</TT>). The <TT>$year</TT>
|
|
will be the full 4-digit year, and <TT>$month</TT> numbers start with 1 (for January).
|
|
|
|
|
|
<P>
|
|
|
|
|
|
In scalar context the numbers are interpolated in a string of the
|
|
``YYYY-MM-DD hh:mm:ss <FONT SIZE="-1">TZ</FONT>''-format and returned.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
If the date is unrecognized, then the empty list is returned (<TT>"undef"</TT> in
|
|
scalar context).
|
|
|
|
|
|
<P>
|
|
|
|
|
|
The function is able to parse the following formats:
|
|
|
|
|
|
<P>
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
"Wed, 09 Feb 1994 22:23:32 GMT" -- HTTP format
|
|
"Thu Feb 3 17:03:55 GMT 1994" -- <A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A>(3) format
|
|
"Thu Feb 3 00:00:00 1994", -- ANSI C asctime() format
|
|
"Tuesday, 08-Feb-94 14:15:29 GMT" -- old rfc850 HTTP format
|
|
"Tuesday, 08-Feb-1994 14:15:29 GMT" -- broken rfc850 HTTP format
|
|
|
|
"03/Feb/1994:17:03:55 -0700" -- common logfile format
|
|
"09 Feb 1994 22:23:32 GMT" -- HTTP format (no weekday)
|
|
"08-Feb-94 14:15:29 GMT" -- rfc850 format (no weekday)
|
|
"08-Feb-1994 14:15:29 GMT" -- broken rfc850 format (no weekday)
|
|
|
|
"1994-02-03 14:15:29 -0100" -- ISO 8601 format
|
|
"1994-02-03 14:15:29" -- zone is optional
|
|
"1994-02-03" -- only date
|
|
"1994-02-03T14:15:29" -- Use T as separator
|
|
"19940203T141529Z" -- ISO 8601 compact format
|
|
"19940203" -- only date
|
|
|
|
"08-Feb-94" -- old rfc850 HTTP format (no weekday, no time)
|
|
"08-Feb-1994" -- broken rfc850 HTTP format (no weekday, no time)
|
|
"09 Feb 1994" -- proposed new HTTP format (no weekday, no time)
|
|
"03/Feb/1994" -- common logfile format (no time, no offset)
|
|
|
|
"Feb 3 1994" -- Unix 'ls -l' format
|
|
"Feb 3 17:03" -- Unix 'ls -l' format
|
|
|
|
"11-15-96 03:52PM" -- Windows 'dir' format
|
|
|
|
</PRE>
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
|
|
The parser ignores leading and trailing whitespace. It also allow the
|
|
seconds to be missing and the month to be numerical in most formats.
|
|
|
|
|
|
<P>
|
|
|
|
|
|
If the year is missing, then we assume that the date is the first
|
|
matching date <I>before</I> current month. If the year is given with only
|
|
2 digits, then <B>parse_date()</B> will select the century that makes the
|
|
year closest to the current date.
|
|
<DT id="4">time2iso( [$time] )<DD>
|
|
|
|
|
|
Same as <B>time2str()</B>, but returns a ``YYYY-MM-DD hh:mm:ss''-formatted
|
|
string representing time in the local time zone.
|
|
<DT id="5">time2isoz( [$time] )<DD>
|
|
|
|
|
|
Same as <B>time2str()</B>, but returns a ``YYYY-MM-DD hh:mm:ssZ''-formatted
|
|
string representing Universal Time.
|
|
</DL>
|
|
<A NAME="lbAF"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
``time'' in perlfunc, Time::Zone
|
|
<A NAME="lbAG"> </A>
|
|
<H2>AUTHOR</H2>
|
|
|
|
|
|
|
|
Gisle Aas <<A HREF="mailto:gisle@activestate.com">gisle@activestate.com</A>>
|
|
<A NAME="lbAH"> </A>
|
|
<H2>COPYRIGHT AND LICENSE</H2>
|
|
|
|
|
|
|
|
This software is copyright (c) 1995-2019 by Gisle Aas.
|
|
<P>
|
|
|
|
This is free software; you can redistribute it and/or modify it under
|
|
the same terms as the Perl 5 programming language system itself.
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="6"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="7"><A HREF="#lbAC">VERSION</A><DD>
|
|
<DT id="8"><A HREF="#lbAD">SYNOPSIS</A><DD>
|
|
<DT id="9"><A HREF="#lbAE">DESCRIPTION</A><DD>
|
|
<DT id="10"><A HREF="#lbAF">SEE ALSO</A><DD>
|
|
<DT id="11"><A HREF="#lbAG">AUTHOR</A><DD>
|
|
<DT id="12"><A HREF="#lbAH">COPYRIGHT AND LICENSE</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:45 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|