Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    8

    Unanswered: date time in perl

    hi ,
    I need some help in converting date to seconds using some perl command.
    My date is in format:

    Mon Jan 31 13:27:42 CST 2005

    I need to convert this to seconds starting from say some reference value in 1970.

    This is just same as format returned using date in unix.
    PLEASE help.

    Thanks,
    Kc132

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Call me lazy, but I'd use:
    Code:
    print time;
    -PatP

  3. #3
    Join Date
    Jan 2005
    Posts
    8

    converting date to seconds

    does time function in perl take arguments? if yes,,how do i specify it?
    can the argument be in the form :

    Mon Jan 31 14:35:13 CST 2005

    Thanks.

  4. #4
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Code:
    #! /usr/bin/perl
    
    use strict;
    use warnings;
    use Time::Local;
    
    my %months   = (Jan => 0,
                    Feb => 1,
                    Mar => 2,
                    Apr => 3,
                    May => 4,
                    Jun => 5,
                    Jul => 6,
                    Aug => 7,
                    Sep => 8,
                    Oct => 9,
                    Nov => 10,
                    Dec => 11,);
    
    my $date = 'Mon Jan 31 14:35:13 CST 2005';
    my (undef,$mon,$day,$time,undef,$year) = split(/\s+/,$date);
    
    my ($h,$m,$s) = split(/:/,$time);
    
    print timelocal($s,$m,$h,$day,$months{$mon},($year-1900));
    board.perl-community.de - The German Perl-Community

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •