Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Turn date string into timestamp?

by shmem (Canon)
on Jul 17, 2007 at 17:41 UTC ( #627084=note: print w/ replies, xml ) Need Help??


in reply to Turn date string into timestamp?

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}


Comment on Re: Turn date string into timestamp?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://627084]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2013-05-19 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (397 votes), past polls