Date::Parse3pm
Parse date strings into time values
Usage
use Date::Parse;my $date = "Wed, 16 Jun 94 07:29:35 CST";my $time = str2time($date);my ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date);
Version
version 2.35
Overview
"Date::Parse" provides two routines for parsing date strings into time values.
- str2time(DATE [, ZONE [, EPOCH]])
-
"str2time"parses"DATE"and returns a unix time value, or undef upon failure."ZONE", if given, specifies the timezone to assume when parsing if the date string does not specify a timezone."EPOCH", if given, is a unix epoch value used as the reference time when filling in missing date components (month, day, or year). Defaults totime(). Useful when the current system clock cannot be trusted or when parsing dates relative to a known reference point.
- strptime(DATE [, ZONE])
-
"strptime"takes the same arguments as str2time but returns an array of values"($ss,$mm,$hh,$day,$month,$year,$zone,$century)". Elements are only defined if they could be extracted from the date string. An empty array is returned upon failure.The return values follow the same conventions as Perl's built-in
"localtime"and"gmtime"functions:- $month
-
0-indexed: 0 = January, 1 = February, ..., 11 = December.
- $year
-
Years since 1900. For example, the year 2015 is returned as
115, and 1995 is returned as95. To recover the full 4-digit year:"$year + 1900".
- $zone
-
Timezone offset in seconds from UTC, or
"undef"if no timezone was specified in the input string.
- $century
-
Defined only when a 4-digit year was present in the input. Its value is
"int($full_year / 100)"(e.g.20for the year 2015). When$centuryis defined,"$year + 1900"gives the original 4-digit year.
For example,
strptime("2015-01-24T09:08:17")returns:($ss, $mm, $hh, $day, $month, $year, $zone, $century)( 17, 8, 9, 24, 0, 115, undef, 20 )# ^--- January (0-indexed)# ^--- 2015 - 1900# ^--- not in input# ^--- int(2015/100)
Multi-language support
Date::Parse is capable of parsing dates in several languages, these include English, French, German and Italian.
$lang = Date::Language->new('German');$lang->str2time("25 Jun 1996 21:09:55 +0100");
Example dates
Below is a sample list of dates that are known to be parsable with Date::Parse
1995-01-24T09:08:17.1823213 ISO-8601Wed, 16 Jun 94 07:29:35 CST Comma and day name are optionalThu, 13 Oct 94 10:13:13 -0700Wed, 9 Nov 1994 09:50:32 -0500 (EST) Text in ()'s will be ignored.21 dec 17:05 Will be parsed in the current time zone21-dec 17:0521/dec 17:0521/dec/93 17:051999 10:02:18 "GMT"16 Nov 94 22:28:20 PST
Copyright and license
This software is copyright (c) 2020 by Graham Barr.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Releases
16 releases since Debian 2.0 (Hamm); the text changed 11 times.