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

Hi I need to make perl program which uses the system time and date. Now how can I extract the time and date in perl? Which are the module(s) that are required? Now as they say, in perl there are many ways to do a thing. So please tell me the easiest way to do this :) Thanks
  • Comment on Extract System Time & Date in a perl so that it can be used in a perl program

Replies are listed 'Best First'.
Re: Extract System Time & Date in a perl so that it can be used in a perl program
by davorg (Chancellor) on Jan 31, 2006 at 13:34 UTC

    The time function returns the number of seconds since the epoch (usually 1st Jan 1970). The localtime function converts that number into more meaningful units. The strftime function (from the standard module POSIX.pm) is useful for formatting dates and times.

    That should get you started, beyond that, take a look at the modules produced by the Perl Date/Time project.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      davorg++ POSIX++ strftime++

      I always use strftime and print out using ISO 8601 time format, here is a swift example

      > perl -MPOSIX -le'print strftime("%Y-%m-%d %X", localtime)' 2006-01-31 18:13:37

      If you print your times in this format it makes them easy to compare or sort with gt/lt

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!
Re: Extract System Time & Date in a perl so that it can be used in a perl program
by blazar (Canon) on Jan 31, 2006 at 14:10 UTC
    So please tell me the easiest way to do this

    time! Also interesting: localtime.