On 03 Apr 2002 00:12:11 +0200 Kjetil Torgrim Homme wrote:
+------------------
| Graham Barr <gb...@po...> writes:
|
| > This is really off-topic for this list, but see Data::Parse and
| > Date::Format
|
| Yeah (and learn to use http://search.cpan.org), but this reminds me
| there is no module with code for converting to/from GeneralizedTime.
| Not that it's very hard to write, but it would be nice to put routines
| for stuff like this in a module. I'm sure there are other syntaxes
| who could use utility functions which fit in.
|
| I can volunteer my code as a start :-)
+------------------
Sorry for the late follow up. I tripped over this problem recently
and just found the thread while researching a solution. I found
no CPAN Time:: or Date:: parser immediately ready for this task. My
code to take the timestamp into epoch seconds is below.
Comments welcome
--
use Time::Local;
#
# 20020411013841Z
# YYYYMMDDhhmmss
# 0....+....1....+
#
sub timestamp_to_epoch {
my $ts = shift;
my ( $year, $month, $day, $hour, $minute, $sec ) = (
substr( $ts, 0, 4 ),
substr( $ts, 4, 2 ),
substr( $ts, 6, 2 ),
substr( $ts, 8, 2 ),
substr( $ts, 10, 2 ),
substr( $ts, 12, 2 )
);
return timegm( $sec, $minute, $hour, $day, $month - 1, $year - 1900 );
}
|