Today's Date in Perl in MM/DD/YYYY format

后端 未结 7 1197
醉酒成梦
醉酒成梦 2020-12-24 11:18

I\'m working on a Perl program at work and stuck on (what I think is) a trivial problem. I simply need to build a string in the format \'06/13/2012\' (always 10 characters,

7条回答
  •  离开以前
    2020-12-24 11:31

    Formating numbers with leading zero is done easily with "sprintf", a built-in function in perl (documentation with: perldoc perlfunc)

    use strict;
    use warnings;
    use Date::Calc qw();
    my ($y, $m, $d) = Date::Calc::Today();
    my $ddmmyyyy = sprintf '%02d.%02d.%d', $d, $m, $y;
    print $ddmmyyyy . "\n";
    

    This gives you:

    14.05.2014

提交回复
热议问题