Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: convert local time to unix epoch time

by poolpi (Hermit)
on Feb 03, 2009 at 20:09 UTC ( #741113=note: print w/replies, xml ) Need Help??


in reply to convert local time to unix epoch time

See DateTime

#!/usr/bin/perl use strict; use warnings; use DateTime; #DateTime->DefaultLocale( 'fr_Fr' ) ; # if needed my $now = DateTime->now( time_zone => 'Europe/Paris' ); print $now->epoch, "\n";


hth,
PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Replies are listed 'Best First'.
Re^2: convert local time to unix epoch time
by ikegami (Pope) on Feb 03, 2009 at 21:43 UTC

    The following would be more appropriate.

    my $now = DateTime->now( time_zone => 'local' );

    Update: Fixed case.

      From DateTime doc:

      The time_zone parameter can be either a scalar or a DateTime::TimeZone object. A string will simply be passed to the DateTime::TimeZone->new method as its "name" parameter. This string may be an Olson DB time zone name ("America/Chicago"), an offset string ("+0630"), or the words "floating" or "local". See the DateTime::TimeZone documentation for more details.

      From DateTime::TimeZone :

      If the "name" parameter is "local", then the module attempts to determine the local time zone for the system.
      If a local time zone is not found, then an exception will be thrown.


      ...For me, at least, it throws actually an exception ;)


      hth,
      PooLpi

      'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

        Then you should have answered the OP and explained that it doesn't work for you before giving the workaround for your system and passing it off the solution.

        Note that it works fine for me on the Windows and linux systems on which I tried it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://741113]
help
Chatterbox?
[Your Mother]: “I’m afraid of Americans…”
[Your Mother]: “No one needs anyone / They don’t even just pretend…”
[erix]: they've stuck nuclear missiles in Kaliningrad - they can just reach Berlin :)
[LanX]: naaah! Putin wouldn't nuke all the Russians in Berlin
[Your Mother]: Putin is a bad guy but he’s not that kind of bad guy. (Who would launch.)
[erix]: fortunately, Putin seems to be ill -- or at least, they're building a hospital for him and his cronies in Moscow
[erix]: nobody knows what kind it takes :)
[erix]: I say his seems a face that launches a thousand missiles :)
[Your Mother]: I say I do. :P
[Your Mother]: Missiles would be an idiot’s play. Putin is many things but he is not an idiot.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-01-20 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (173 votes). Check out past polls.