convert the systemdate in iso 8601 format in perl

iso8601, perl

Solution

You should use `gmtime()` instead of `localtime()` to get the broken-down time values in UTC.

use POSIX qw(strftime);
my $now = time();
print strftime('%Y-%m-%dT%H:%M:%SZ', gmtime($now)), "\n";

output:

2014-06-04T10:17:17Z

Problem

I want the system date to be converted to ISO 8601 format. code: ``` my $now = time(); my $tz = strftime("%z", localtime($now)); $tz =~ s/(\d{2})(\d{2})/$1:$2/; print "Time zone *******-> \"$tz\"\n"; # ISO8601 my $currentDate = strftime("%Y-%m-%dT%H:%M:%S", localtime($now)) . $tz; print "Current date *******-> \"$currentDate\"\n"; ``` Current output is: ``` Time zone *******-> "-04:00" Current date *******-> "2014-06-03T03:46:07-04:00" ``` I want the current date to be in format "2014-07-02T10:48:07.124Z", So that I can compute the difference between the two.

Original source