I want the system date to be converted to the 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:
Time zone *******-> "-04:00" Current date *******-> "2014-06-03T03:46:07-04:00"
I want the current date to be in the format "2014-07-02T10: 48: 07.124Z" so that I can calculate the difference between the two.
Perl DateTimepackage ( in CPAN ) can give you ISO8601 dates very easily, but with one caveat.
DateTime
, DateTime, UTC, . , , ISO8601, , UTC. , . , Z , DateTime, , :
Z
use DateTime; my $now = DateTime->now()->iso8601().'Z';
:: . :: Perl 2007 .
#!/usr/bin/perl use strict; use warnings; use 5.010; use Time::Piece; my $time = localtime; say $time->datetime; # Time in ISO8601 format say $time->tzoffset; # Time zone offset in seconds # But tzoffset actually returns a Time::Seconds object say $time->tzoffset->hours; # Time zone offset in hours (for example)
gmtime() localtime(), UTC.
gmtime()
localtime()
my $now = time(); print strftime('%Y-%m-%dT%H:%M:%SZ', gmtime($now)), "\n";
:
2014-06-04T10:17:17Z
Source: https://habr.com/ru/post/1543022/More articles:Close an old application instance - c #How to prevent Delete Sucessfully after kendo mesh destruction? - jqueryWhy do I have a backbone. $ = Require ('jquery') in the browser - jqueryInsert an object (as a folder) into Google Cloud Storage using the JSON API with Java - javaRunning java in 32-bit mode on Windows 64 - javaWhy is IIS slower at first access, but faster? - asp.netSharePoint Hosted App - создание каскадного раскрывающегося списка в размещенных веб-списках - sharepointmessage box over splashing screen - c #How .net - .netThe priority value in the reactive (), as in the observation mode () (R Shiny) - rAll Articles