http://qs321.pair.com?node_id=401260


in reply to How can I format the output of localtime?

This is an update of Roy Johnson's great answer, for those who just want the current time formatted in m/d/y.
my ($d,$m,$y) = (localtime)[3,4,5]; my $mdy = sprintf '%d/%d/%d', $m+1, $d, $y+1900;
Or if month and day should always be two digits:
my $mdy = sprintf '%02d/%02d/%04d', $m+1, $d, $y+1900;

Replies are listed 'Best First'.
Re: Answer: How can I format the output of localtime?
by johnnywang (Priest) on Oct 21, 2004 at 18:44 UTC
    if you want two digits for day/month like 04/03/2004, then
    my ($d,$m,$y) = (localtime(time))[3,4,5]; my $mdy = sprintf '%02d/%02d/%d', $m+1, $d, $y+1900;
      Update: Roy Johnson just notified me that localtime doesn't need any parameters to give the current time. On a different note, why aren't any of these replies appearing in the larger Q&A thread with the rest of the answers?
        Because Q&A answers are contributed content. Once they are posted, the maintainers of the section can edit or delete them at will, or combine several answers into one, etc. Given this, it doesn't make sense to show the replies which may no longer be relevant. They are still visible when looking at an individual answer, because normally you would be looking at a question and it's answers together.

        (That's my guess, or at any rate an argument for not changing it. It's equally likely to have originally been a bug.)