开发者

How to convert date-time srings from different timezones into integer to find most recent i.e. maximum of integer in perl?

I have date-time strings in the below format

[yyyymmddhhmmss+TZ] "20110711114445+08", "20110711114445+05.30". 

How should i find out which is most recent date-time string ? I want all of the string to convert into a single time-zone and then convert the strings into integer to find out ma开发者_运维问答ximum integer. Help me out ?


You can use DateTime::Format::Strptime to parse the date-time strings into DateTime objects. Once you have the objects, you can compare them as ordinary integers.

use DateTime::Format::Strptime;
use List::Util 'max';

my $Strp = new DateTime::Format::Strptime(pattern => '%Y%m%d%H%M%S%z');
my @objects = map $Strp->parse_datetime($_), @strings;
my $dt = max(@objects);


The Date::Calc can help you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜