timegm()

Discussion in 'Perl Misc' started by Gauri, Jun 26, 2007.

  1. Gauri

    Gauri Guest

    This is the time I have in GMT
    time: 6/26/2007 12:00:26 AM

    I want to convert it to epoch format in CST timezone:
    Using the timegm() function, this is the answer I get:
    GMT_epochtime: 1182859226

    Is CST_epochtime same as GMT_epochtime for any given time?

    Also when I try to convert the above epoch time back to readable time,
    using function gmtime()
    ($r_sec,
    $r_min,
    $r_hour,
    $r_day,
    $r_month,
    $r_year,
    $r_weekday,
    $r_yearday,
    $r_isdst) = gmtime($GMT_epochtime);

    I get $r_hour = 12.

    I'm expecting 00 since the time given above is 12 AM.

    Where am I going wrong? else how do I know if $r_hour =12 is AM or PM?

    -Gauri
     
    Gauri, Jun 26, 2007
    #1
    1. Advertising

  2. Gauri wrote:
    > This is the time I have in GMT
    > time: 6/26/2007 12:00:26 AM
    >
    > I want to convert it to epoch format in CST timezone:
    > Using the timegm() function, this is the answer I get:
    > GMT_epochtime: 1182859226


    Then you don't pass the correct values to timegm().

    C:\home>type test.pl
    use Time::Local;
    print timegm( 26, 0, 0, 26, 6-1, 2007 ), "\n";

    C:\home>test.pl
    1182816026

    C:\home>

    > Is CST_epochtime same as GMT_epochtime for any given time?


    Yes.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jun 27, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page