[Solved] perl different time format output


Use Time::Piece. It’s a standard part of the Perl distribution. Use strptime (string parse time) to parse your string into a Time::Piece object. Then use strftime (string format time) to display your Time::Piece object in whatever format you want.

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Time::Piece;

my $in_format="%Y-%m-%d %H:%M:%S";
my $out_format="%Y-%m-%dT%H:%M:%SZ";

my $in_date="2015-08-18 08:51:00";

my $date = Time::Piece->strptime($in_date, $in_format);

say $date->strftime($out_format);

4

solved perl different time format output