#! /usr/bin/perl -w #--------------------------------------------------------------------- # $Id: mktime.pl 1756 2007-04-11 05:12:43Z cjm $ # Copyright 2007 Christopher J. Madsen # # This program is free software; you can redistribute it and/or modify # it under the same terms as Perl itself. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the # GNU General Public License or the Artistic License for more details. # # Convert between UNIX time format and calendar dates #--------------------------------------------------------------------- die "Usage: mktime DATE\n" unless @ARGV; $_ = join(' ',@ARGV); my ($time,$date); if (/^[0-9]+$/i) { $time = $_; } elsif (/^(?:0x)?[0-9A-F]+$/i) { $time = hex $_; } else { require Time::ParseDate; $time = Time::ParseDate::parsedate($_, PREFER_FUTURE => 1); die "`$_' is not a valid date" unless $time; } $_ = sprintf("0x%X => %d", $time, $time); printf("%s => %s\n%s => %s GMT\n", $_, scalar localtime $time, ' ' x length $_, scalar gmtime $time);