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

Is there any function available to convert the local time to Unix epoch time ?

Replies are listed 'Best First'.
Re: convert local time to unix epoch time
by Corion (Patriarch) on Feb 03, 2009 at 10:14 UTC
      gmtime function will suite for your scenario. Please check the CPAN module Date::Calc and Date::Manip for further more details.
Re: convert local time to unix epoch time
by poolpi (Hermit) on Feb 03, 2009 at 20:09 UTC

    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

      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