1Date::Parse(3) User Contributed Perl Documentation Date::Parse(3)
2
3
4
6 Date::Parse - Parse date strings into time values
7
9 use Date::Parse;
10
11 $time = str2time($date);
12
13 ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date);
14
16 "Date::Parse" provides two routines for parsing date strings into time
17 values.
18
19 str2time(DATE [, ZONE])
20 "str2time" parses "DATE" and returns a unix time value, or undef
21 upon failure. "ZONE", if given, specifies the timezone to assume
22 when parsing if the date string does not specify a timezone.
23
24 strptime(DATE [, ZONE])
25 "strptime" takes the same arguments as str2time but returns an
26 array of values "($ss,$mm,$hh,$day,$month,$year,$zone,$century)".
27 Elements are only defined if they could be extracted from the date
28 string. The $zone element is the timezone offset in seconds from
29 GMT. An empty array is returned upon failure.
30
32 Date::Parse is capable of parsing dates in several languages, these
33 include English, French, German and Italian.
34
35 $lang = Date::Language->new('German');
36 $lang->str2time("25 Jun 1996 21:09:55 +0100");
37
39 Below is a sample list of dates that are known to be parsable with
40 Date::Parse
41
42 1995:01:24T09:08:17.1823213 ISO-8601
43 1995-01-24T09:08:17.1823213
44 Wed, 16 Jun 94 07:29:35 CST Comma and day name are optional
45 Thu, 13 Oct 94 10:13:13 -0700
46 Wed, 9 Nov 1994 09:50:32 -0500 (EST) Text in ()'s will be ignored.
47 21 dec 17:05 Will be parsed in the current time zone
48 21-dec 17:05
49 21/dec 17:05
50 21/dec/93 17:05
51 1999 10:02:18 "GMT"
52 16 Nov 94 22:28:20 PST
53
55 Date::Parse uses Time::Local internally, so is limited to only parsing
56 dates which result in valid values for Time::Local::timelocal. This
57 generally means dates between 1901-12-17 00:00:00 GMT and 2038-01-16
58 23:59:59 GMT
59
61 When both the month and the date are specified in the date as numbers
62 they are always parsed assuming that the month number comes before the
63 date. This is the usual format used in American dates.
64
65 The reason why it is like this and not dynamic is that it must be
66 deterministic. Several people have suggested using the current locale,
67 but this will not work as the date being parsed may not be in the
68 format of the current locale.
69
70 My plans to address this, which will be in a future release, is to
71 allow the programmer to state what order they want these values parsed
72 in.
73
75 Graham Barr <gbarr@pobox.com>
76
78 Copyright (c) 1995-2009 Graham Barr. This program is free software; you
79 can redistribute it and/or modify it under the same terms as Perl
80 itself.
81
82
83
84perl v5.34.0 2022-01-21 Date::Parse(3)