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

Currently I am getting the system timeusing the below code which gives time as "392011",I want the time as "030911",Can anyone suggest how can I achieve that?

my ($sec,$min,$hour,$day,$mon,$yr19,@rest) = localtime(time);####### +To get the localtime of your system my $month =$mon +1; my $year =$yr19+1900; print "$month$day$year\n";

Replies are listed 'Best First'.
Re: Getting system time in a specific format
by GrandFather (Saint) on Mar 10, 2011 at 03:27 UTC
    my ($sec,$min,$hour,$day,$mon,$year,@rest) = localtime(time); ++$mon; $year += 1900; printf "%02d%02d%04d\n", $mon, $day, $year;

    Note however that the string of digits thus produced can be ambiguous out of context. If you have a degree of control over the format you'd be better to use YYYY-MM-DD or YYYYMMDD.

    True laziness is hard work
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Getting system time in a specific format
by ikegami (Patriarch) on Mar 10, 2011 at 05:08 UTC
    use POSIX qw( strftime ); my $date = strftime("%m%d%y", localtime);
Re: Getting system time in a specific format
by Anonymous Monk on Mar 10, 2011 at 03:22 UTC