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

How does one tell time in perl. I can get the seconds since 1970 time but I would like to get a current time. Is there a simple way that I can do this?

Replies are listed 'Best First'.
Re: Time in Perl
by belg4mit (Prior) on Apr 28, 2002 at 01:46 UTC
    There is, as the manual points out localtime will do what you seek.

    --
    perl -pew "s/\b;([mnst])/'$1/g"

Re: Time in Perl (examples in PerlMonks Q&A dates-and-times section, plus (s)printf)
by ybiC (Prior) on Apr 28, 2002 at 02:36 UTC

    As good monk belg4mit said, localtime is likely may be what you're looking for. The local perldoc is your friend, as is the PerlMonks search form at the upper left.   But to get you started, try QandASection: dates and times, which contains several examples that may help.

    Update: Depending on what you're going to do with your human-readable date/timestamp, printf (print a formatted string) and sprintf (return a formatted string) may also be worth delving into.

    Oh yeah, and welcome to the Monastery!
        cheers,
        Don
        striving toward Perl Adept
        (it's pronounced "why-bick")
      To add a bit to what brother ybiC states there is another function that has made my life piles easier.
      use POSIX; print strftime("%Y-%m-%d %H:%M:%S", localtime),"\n"; # This displays the following: # 2002-04-28 10:52:32 # (Assuming I ran this when I was typing. {g})
      Do a man strftime to find out what all the formats are.

      {NULE}
      --
      http://www.nule.org

Re: Time in Perl
by mattr (Curate) on Apr 28, 2002 at 16:29 UTC
    I usually think, "print scalar localtime". Or you can use Time::HiRes if you want to be absolutely clear.