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

Sean Baker pbaker at omnihotels.com
Fri Sep 29 06:44:20 PDT 2006


#!/usr/bin/perl


Sean Baker
Software Architect
Omni Hotels
(402) 952-6508
pbaker at omnihotels.com
-----Original Message-----
From: omaha-pm-bounces+pbaker=omnihotels.com at pm.org
[mailto:omaha-pm-bounces+pbaker=omnihotels.com at pm.org] On Behalf Of Jay
Hannah
Sent: Friday, September 29, 2006 8:15 AM
To: omaha-pm at pm.org
Subject: [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 at omnihotels.com>
Date: Fri, 29 Sep 2006 08:13:07 -0500
To: "OTA-Impl-Forum at googlegroups.com" <OTA-Impl-Forum at 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

_______________________________________________
Omaha-pm mailing list
Omaha-pm at pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm



More information about the Omaha-pm mailing list