Simple way to format date

前端 未结 4 1289
悲哀的现实
悲哀的现实 2021-01-22 12:54

I wrote a perl script to get datetime. It do work but I do wonder if there any easier way to format date as output.

#!/usr/bin/perl
use DateTime;

my $dt                 


        
4条回答
  •  猫巷女王i
    2021-01-22 13:42

    DateTime provides the format_cldr method for this:

    use DateTime;
    
    my $myTimeStamp = DateTime->now->subtract( days => 1 );
    
    printf "--> %s\n", $myTimeStamp->format_cldr('yyyy MM dd HH');
    # --> 2012 02 28 02
    

提交回复
热议问题