[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Perl: datetime stamps (2006-09-28T18:38:07.97-05:00)



Can anyone one up me?

J



------ Forwarded Message
From: Jay Hannah <jhannah@omnihotels.com>
Date: Fri, 29 Sep 2006 08:13:07 -0500
To: "OTA-Impl-Forum@googlegroups.com" <OTA-Impl-Forum@googlegroups.com>
Subject: Perl: datetime stamps (2006-09-28T18:38:07.97-05:00)

Here's a little Perl routine to kick out datetime stamps in the OTA
format. If anyone has a better/tighter/faster Perl routine, do tell. :)

(And/or share your solutions in other languages just for fun.)

Cheers,

j


$ cat j.pl
use strict;
use Date::Calc;
use Time::HiRes;

my ($s, $usec) = Time::HiRes::gettimeofday();
my @offset = Date::Calc::Timezone();
my ($Dh, $Dm) = @offset[3..4];
my $direction = $Dh > 0 ? "+" : "-";
$Dh = abs $Dh;
my $now = sprintf(
   "%04d-%02d-%02dT%02d:%02d:%02d.%02d%s%02d:%02d",
   Date::Calc::Today_and_Now(),
   substr($usec / 1000000, 2, 2),
   $direction, $Dh, $Dm
);
print "$now\n";

$ perl j.pl
2006-09-28T18:38:07.97-05:00


------ End of Forwarded Message