#!/usr/bin/perl -w # # iso-timestamp # # The ISO date/time format is really nice, and I strongly suggest that # everyone switch to it as soon as they can. Much more information # can be found at: # # http://www.cl.cam.ac.uk/~mgk25/iso-time.html # # Along with his equally geeky coverage of ISO Paper Sizes and Metric # Typography. # # # Copyright (c) 1999 -- Tkil # # This program is free software; you may use, copy, modify, and # distribute it under the same terms as Perl itself. use strict; sub iso_timestamp { my $t = shift || time; my ($sec, $min, $hour, $mday, $mon, $year, $wday,$yday,$isdst) = localtime $t; # read the documentation for "localtime" here. and *never* try to # do C< $year = "19" . $year >!!! $year += 1900; $mon += 1; # the concatenated formatting string is just to help you connect # format codes with their contents. it should be done at compile # time, so there should be no cost at runtime. return sprintf ("%04d"."%02d"."%02d"."%02d"."%02d"."%02d", $year, $mon, $mday, $hour, $min, $sec); } print iso_timestamp(), "\n";