DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Simple Output Of Date In Perl

09.07.2007
| 10024 views |
  • submit to reddit
        // Simple output of current date in perl

  my @day_name = ("Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat.");
  my ($sec,$min,$hour,$mday,$mon,$year,$wday); 
  ($sec,$min,$hour,$mday,$mon,$year,$wday,undef,undef)=localtime(time()); $year+=1900;$mon++;
  $report_date=sprintf("%s %04d.%02d.%02d %02d:%02d",$day_name[$wday],$year,$mon,$mday,$hour,$min);
    

Comments

Snippets Manager replied on Tue, 2007/10/02 - 11:41am

What's wrong with: use POSIX 'strftime'; print strtftime( '%a. %Y.%m.%d %H:%M', localtime(time()) ); ?? After all, the POSIX module is included with the base Perl distribution, no sense in doing all this work yourself when strftime() will do it for you.