#!/usr/bin/perl # epochToDate # This script converts epoch time (seconds since January 1, 1970) to a date. # It expects one command-line argument specifying an epoch time. # It outputs the date corresponding to that epoch time in the format # CCYYMMDDhhmm.SS expected by the 'touch' command. # To get other formats, edit the printf statement in the script. # Cameron Hayne (macdev@hayne.net) March 2006 use warnings; use strict; die "Usage: epochToDate time\n" unless scalar(@ARGV) == 1; my $time = $ARGV[0]; die "Epoch time must be an integer\n" unless $time =~ /^-?\d+$/; my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($time); $year += 1900; $month += 1; # change to range 1..12 instead of 0..11 printf("%04d%02d%02d%02d%02d%02d\n", $year, $month, $day, $hour, $min, $sec);