Keep Unix Timestamp format with Localtime function

Discussion in 'Perl Misc' started by triwolf, Feb 5, 2006.

  1. triwolf

    triwolf Guest

    Is there a way to keep the normal unix timestamp calculated format and
    still use the LocalTime function in Perl?
    Or is there another function for doing something like this.

    I just want to input a unix timestamp and get a unixstamp in local
    time.


    Thanks for your help.



    --Triwolf
     
    triwolf, Feb 5, 2006
    #1
    1. Advertising

  2. triwolf

    Matt Garrish Guest

    "triwolf" <> wrote in message
    news:...
    > Is there a way to keep the normal unix timestamp calculated format and
    > still use the LocalTime function in Perl?


    I really don't understand what you're asking. The localtime (note case)
    function takes a timestamp and returns either a list of values or the ctime
    depending on how it's called. The time function will give you the current
    epoch time.

    my $time = time;
    my $localtime = localtime($time);

    You'd now have both the epoch time and its localtime representation. What's
    your actual problem?

    Matt
     
    Matt Garrish, Feb 5, 2006
    #2
    1. Advertising

  3. triwolf

    Joe Smith Guest

    triwolf wrote:
    > Is there a way to keep the normal unix timestamp calculated format and
    > still use the LocalTime function in Perl?
    > Or is there another function for doing something like this.
    >
    > I just want to input a unix timestamp and get a unixstamp in local
    > time.


    Perl has gmtime() and localtime() build-in functions.
    Have you even tried them?
    -Joe

    cygwin% cat temp.pl
    print "gmtime() in scalar context returns: ".gmtime()."\n";
    print "gmtime() in list context returns: ",join(":",gmtime()),"\n";
    print "TZ = $ENV{TZ}\n";
    print "localtime() in scalar context returns: ".localtime()."\n";
    print "localtime() in list context returns: ",join(":",localtime()),"\n";
    print "See 'perldoc -q date' for more information.\n";

    cygwin% perl temp.pl
    gmtime() in scalar context returns: Mon Feb 6 01:10:58 2006
    gmtime() in list context returns: 58:10:1:6:1:106:1:36:0
    TZ = PST8PDT7,M4.1.0/2,M10.5.0/2
    localtime() in scalar context returns: Sun Feb 5 17:10:58 2006
    localtime() in list context returns: 58:10:17:5:1:106:0:35:0
    See 'perldoc -q date' for more information.
     
    Joe Smith, Feb 6, 2006
    #3
    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.
Similar Threads
  1. OleMacGeezer

    time.localtime() Format Question

    OleMacGeezer, Aug 20, 2006, in forum: Python
    Replies:
    1
    Views:
    486
    Greg Krohn
    Aug 20, 2006
  2. islamelnaggar
    Replies:
    4
    Views:
    3,075
    islamelnaggar
    Feb 24, 2008
  3. islamelnaggar
    Replies:
    0
    Views:
    512
    islamelnaggar
    Feb 24, 2008
  4. Andyza
    Replies:
    6
    Views:
    1,491
    Evertjan.
    Mar 5, 2009
  5. Replies:
    6
    Views:
    381
    Dr J R Stockton
    Mar 6, 2007
Loading...

Share This Page