Let's start with the Rahul snippet and add the date and math output to the format ...
use DateTime; use DateTime::Format::ISO8601; use DateTime::Format::Strptime; my $string = '2011-07-07T18:05:45Z'; my $dt = DateTime::Format::ISO8601->parse_datetime( $string ); die "Impossible time" unless $dt; my $formatter = new DateTime::Format::Strptime(pattern => '%Y-%m-%d %T'); $dt->add( hours => 8 )->set_formatter($formatter); print "$dt\n";
I added the use of DateTime :: Format :: Strptime to specify the desired output format.
Then I added three more lines:
- First I create a formatter and give it the output template that I want.
- Then I add eight hours to the original date, and I assign the output of formatter by associating the set_formatter () call with the add () call.
- Then I print it.
source share