Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

convert my date into local time or epoch time

by kaka_2 (Sexton)
on Oct 28, 2013 at 09:10 UTC ( [id://1059952]=perlquestion: print w/replies, xml ) Need Help??

kaka_2 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I am writing a program which read a file and receives a value (time) from it. for further logic i have to use this time but the time i read is in iso8601 format. Exactly it looks as example "2007-12-24T18:21Z" and This is UTC time.

Can someone tell me how can i convert it to my localtime or epoch time.

Thank You

-KAKA-

  • Comment on convert my date into local time or epoch time

Replies are listed 'Best First'.
Re: convert my date into local time or epoch time (oracle)
by Anonymous Monk on Oct 28, 2013 at 09:51 UTC
      Hello,

      I downloaded the Piece.pm Module and installed on my machine but still i dont get how it can convert date in example to localtime or epoch time.

      Could you share idea

      Thank You.

      -KAKA-

Re: convert my date into local time or epoch time
by chrestomanci (Priest) on Oct 28, 2013 at 12:01 UTC

    DateTime::Format::W3CDTF on CPAN can convert that format for you. Then just call epoch() on the resultant DateTime object.

    eg:

    my $time = DateTime::Format::W3CDTF->parse_datetime("2007-12-24T18:21Z +"); print "epoch time: ".$time->epoch();
Re: convert my date into local time or epoch time
by marinersk (Priest) on Oct 28, 2013 at 13:59 UTC
    LOL -- I am happy to see modules addressing this.

    A long time ago I found myself having to create a reciprocal function for localtime()-- essentially the same as this epoch()function.

    It was an interesting effort, trying to write code to reciprocate perfectly a function whose code was not immediately available to me.

    I opted to go with an estimate-confirm-refine algorithm. It zeroed in on the epoch value which would return the exact results from localtime()as was provided by the input.

    It was kind of fun to write.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1059952]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-26 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found