On May 31, Ahmer Memon said:

>Later on I noticed the sprintf function.  You can use this to format your
>dates and times without cycling through all the elements returned by the
>localtime function.  Anyway I am pasting in a bit from one of my scripts
>that does just this:
>
>($sec,$min,$hour, $day,$mon,$year) = (localtime(time))[0, 1, 2, 3, 4, 5];
>
>$date_time = sprintf("%04u%02u%02u %02u:%02u:%02u",
>                      $year + 1900, $mon + 1,  $day, $hour, $min, $sec);

Most people use %d rather than %u here.

Also, if you're familiar with Unix, you might like using the
strftime() function from POSIX.pm:

  use POSIX 'strftime';

  # localtime's default argument is time()
  $date_time = strftime('%Y%m%d %H', localtime);

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**        I no longer need a publisher for my Perl Regex book :)        **

Reply via email to