DateTime::Format::HTTP supports that format (as the "ANSI C asctime()" format). You need to add a four-digit year on the end to be completely accurate, but it can handle it if you don't (according to the documentation).
use DateTime::Format::HTTP;
my $dt = DateTime::Format::HTTP->parse_datetime("Thu Jan 8 07:01:01");
From there, you can convert to anything else in the DateTime::Format:: namespace.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
: () { :|:& };:
Note: All code is untested, unless otherwise stated
| [reply] [d/l] [select] |
NAME
Time::Local - efficiently compute time from local and GMT time
SYNOPSIS
$time = timelocal($sec,$min,$hour,$mday,$mon,$year);
$time = timegm($sec,$min,$hour,$mday,$mon,$year);
DESCRIPTION
These routines are the inverse of built-in perl functions localtime()
and gmtime(). They accept a date as a six-element array, and return
the corresponding time(2) value in seconds since the Epoch (Midnight,
January 1, 1970). This value can be positive or negative.
...
--
TTTATCGGTCGTTATATAGATGTTTGCA
| [reply] |
Check Date::Manip. Converts just about any format of date/time into any other. Also uses common words to do the conversions. The perldoc on this is quite extensive. Take a look.
| [reply] |
This is hard to do, since you give no year! But for the case that the year is there at the end you can use this:
use Date::Calc qw/:all/;
my $str = "Thu Jan 8 07:01:05 2004";
$time = Date_to_Time(Parse_Date($str), $str =~ /(\d\d):(\d\d):(\d\d)/
+);
| [reply] [d/l] |
Provided you also provide the year, it is easy: use Time::Local;
my $timestring='Thu Jan 8 07:01:01';
my (undef,$mon,$mday,$hour,$min, $sec)=split / |:/, $timestring;
my $year=2004;
my $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
print "$timestring = $time = " . scalar(localtime($time));
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] [d/l] |
I use Date::Parse, it is lightweight and doesn't need a year in the string.
| [reply] |
Time::Piece rocks at this kind of stuff.
If you don't supply a year, T::P picks 1970:
use Time::Piece;
my $date = localtime->strptime("Thu Jan 8 07:01:01",'%a %b %d %T');
print $date . "\n";
You can default to the current year (or any year for that matter) like so:
use Time::Piece;
my $year = localtime->year;
my $date = localtime->strptime("Thu Jan 8 $year 07:01:01",'%a %b %d %Y
+ %T');
print $date . "\n";
| [reply] [d/l] [select] |
use HTTP::Date;
my $stamp = str2time $timestr;
Makeshifts last the longest.
| [reply] [d/l] |