Date::Parse is nothing new, but I haven't ever really needed it until recently when I had to sort a bunch of date strings.

The dates I need to play look like Sun, 25 Apr 2004 16:08:05 +0200. Sometimes they have the time zone, sometimes they don't. Often they have a lot of different time zones.

Small matter to Date::Parse::str2time()

use Date::Parse qw(str2time); my $date = 'Sun, 25 Apr 2004 16:08:05 +0200'; my $epoch_time = str2time( $date );

Once I have the epoch time, it's easy to go back the other way too, using Date::Format, also in the TimeDate package.

--
brian d foy <bdfoy@cpan.org>

Replies are listed 'Best First'.
Re: New Favorite Thing: str2time
by Zaxo (Archbishop) on Sep 28, 2004 at 20:20 UTC

    I like POSIX::strftime() with localtime for going the other direction.

    After Compline,
    Zaxo

Re: New Favorite Thing: str2time
by TedYoung (Deacon) on Sep 28, 2004 at 20:27 UTC

    Yea, I love Date::Parse and Date::Format too. I use Date::Parse for most of my CGI applications when asking for a date. Why restrict the user to a single date format when you can easily bow to their comfort?

    Well... OK, there are times when you really need/want to force a user to enter a date in a certain format, but for most of my stuff, it doesn't matter. All I care about is epoch time.

    -ted

Re: New Favorite Thing: str2time
by sshipway (Initiate) on Jul 10, 2014 at 04:32 UTC
    My problem is that it defaults to assuming American date format, so 01/12/14 gets parsed as 12th January rather than 1st December. There is no way to make is default to 'non-USA' mode, which can cause a few issues when people are not aware of it. It is very good at getting other things correct, though, even if parts are missing.