| [reply] [Watch: Dir/Any] |
If convenience is more important than size (Date::Manip is
about 240k of Perl code), you could do
use Date::Manip;
my $time = UnixDate('2007/07/17 13:21', "%s");
print "time=$time\n"; # 1184671260
| [reply] [Watch: Dir/Any] [d/l] [select] |
Well, not for all "like" strings, but for exactly that format, I'd do something like
use Time::Local;
my $str = '2007/07/17 13:21';
my @t = $str =~ m!(\d{4})/(\d{2})/(\d{2})\s(\d{2}):(\d{2})!;
$t[1]--;
my $timestamp = timelocal 0,@t[4,3,2,1,0];
# verify...
print scalar localtime $timestamp;
__END__
Tue Jul 17 13:21:00 2007
before looking up any module of CPAN. Things would be different if I had to convert disparate formats.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [Watch: Dir/Any] [d/l] |
use strict;
use warnings;
use DateTime::Format::Strptime;
my $str = '2007/07/17 13:21';
my $parser =
DateTime::Format::Strptime->new( pattern => '%Y/%m/%d %H:%M' );
my $dt = $parser->parse_datetime( $str );
print $dt->epoch;
__END__
C:\src\perl\perlmonks\627080>perl -w 627080.pl
1184678460
| [reply] [Watch: Dir/Any] [d/l] |
Really? I've been referring to these as a date string and a unix timestamp.
| [reply] [Watch: Dir/Any] |