12 Dec 2009 12:42:26 UTC
- Distribution: TimeDate
- Module version: 2.30
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (39)
- Testers (4147 / 42 / 0)
- KwaliteeBus factor: 1
- License: perl_5
- Download (28.9KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:10 non-PAUSE users
Date::Parse - Parse date strings into time values
use Date::Parse; $time = str2time($date); ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date);
Date::Parseprovides two routines for parsing date strings into time values.
- str2time(DATE [, ZONE])
DATEand 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.
- strptime(DATE [, ZONE])
strptimetakes the same arguments as str2time but returns an array of values
($ss,$mm,$hh,$day,$month,$year,$zone). Elements are only defined if they could be extracted from the date string. The
$zoneelement is the timezone offset in seconds from GMT. An empty array is returned upon failure.
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");
Below is a sample list of dates that are known to be parsable with Date::Parse
1995:01:24T09:08:17.1823213 ISO-8601 1995-01-24T09:08:17.1823213 Wed, 16 Jun 94 07:29:35 CST Comma and day name are optional Thu, 13 Oct 94 10:13:13 -0700 Wed, 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 zone 21-dec 17:05 21/dec 17:05 21/dec/93 17:05 1999 10:02:18 "GMT" 16 Nov 94 22:28:20 PST
Date::Parse uses Time::Local internally, so is limited to only parsing dates which result in valid values for Time::Local::timelocal. This generally means dates between 1901-12-17 00:00:00 GMT and 2038-01-16 23:59:59 GMT
When both the month and the date are specified in the date as numbers they are always parsed assuming that the month number comes before the date. This is the usual format used in American dates.
The reason why it is like this and not dynamic is that it must be deterministic. Several people have suggested using the current locale, but this will not work as the date being parsed may not be in the format of the current locale.
My plans to address this, which will be in a future release, is to allow the programmer to state what order they want these values parsed in.
Graham Barr <email@example.com>
Copyright (c) 1995-2009 Graham Barr. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 325:
You forgot a '=back' before '=head1'
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|