#!/usr/bin/perl # Adapted from time.pl from PERL in easy steps, Ch. 8 $machine_time = localtime(time); # local time (there's also gmtime for UT) ($sec, $min, $hr, $mday, $mon, $yr, $wday, $yday, $isdst) = localtime(time); $mon++; # make it start from 1 not 0: month 1-12 $yday++; # make it start from 1 not 0: day of year, 1-365 $yr += 1900; # yr internally starts from 1900, fix that $hr = sprintf("%02d",$hr); # convert it to formatted string $min = sprintf("%02d",$min); # .. $sec = sprintf("%02d",$sec); # .. $ds = ($isdst == 1) ? "Yes":"no"; # convert daylight savings flag to string print << "DOC"; Machine time: $machine_time Date: $mon-$mday-$yr Time: $hr:$min:$sec Daylight saving: $ds Day of week: $wday Day of year: $yday DOC