Reputation: 6259
If today is Jan, 1, 2012, how to return a string of date "20120101' ?
sub getDateStr{
my $date = shift;
print $date->year.$date->month.$date->day."\n";
return $date->year.$date->month.$date->day;
}
Thanks
Upvotes: 1
Views: 2838
Reputation: 6524
use Time::Piece;
$t = localtime()->strftime("%Y%m%d");
or simpler
$t = localtime()->ymd("");
Upvotes: 4
Reputation: 4488
use DateTime;
print DateTime->now->ymd("");
print DateTime->now->strftime("%Y%m%d");
print DateTime->now->format_cldr("yyyyMMdd");
Upvotes: 2