How can I convert dates to required format in Perl?
I have current date as 1/10/2010 I need to convert it into 1 October 2010. Is there any module to convert?
Use DateTime::Format::Strptime
.
use DateTime::Format::Strptime;
my $Strp = DateTime::Format::Strptime->new(
pattern => '%d/%m/%Y',
time_zone => 'UTC',
);
my $dt = $Strp->parse_datetime('1/10/2010');
print $dt->strftime('%d %b %Y');
Edit: Thanks to @davorg for a hint with new
.
You can try:
my $date = '1/10/2010';
my @abbr = qw( dummy Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my($d,$m,$y) = split/\//g,$date;
my $new_date = $d.' '.$abbr[$m].' '.$y;
精彩评论