AcidHawk has asked for the wisdom of the Perl Monks concerning the following question:
This works, but I'm sure the gurus have this in two or three lines as opposed to any many as mine. -----use strict; use warnings; my $d = &Date(); my $t = &Time(); print "$d - $t\n"; #Set Local Date sub Date() { (my $ss, my $mm, my $hh, my $d, my $mon, my $yr) = localtime(); my $date = sprintf("%04d/%02d/%02d", $yr+1900, $mon+1, $d); return($date); } #Set Local Time sub Time() { my ($ampm); (my $ss, my $mm, my $hh, my $d, my $mon, my $yr) = localtime(); if ( $hh > 12 ) { $hh = $hh - 12; $ampm = "PM"; } else { $ampm = "AM"; } my $time = sprintf("%02d:%02d:%02d %s", $hh, $mm, $ss, $ampm); return($time); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: AM/PM in date and time format
by davorg (Chancellor) on Sep 09, 2002 at 13:57 UTC | |
|
Re: AM/PM in date and time format
by cfreak (Chaplain) on Sep 09, 2002 at 13:57 UTC | |
|
Re: AM/PM in date and time format
by davis (Vicar) on Sep 09, 2002 at 14:01 UTC | |
|
Re: AM/PM in date and time format
by greenFox (Vicar) on Sep 09, 2002 at 14:05 UTC | |
|
Re: AM/PM in date and time format
by AcidHawk (Vicar) on Sep 09, 2002 at 14:16 UTC |