开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜