One, for timestamps, usually just time(); is enough. Why pretty format a date you are going to stick in a dB? Work with the time in seconds and save your sanity. Or else look at $time = localtime(); and see if the date string that puts out is good enough. localtime puts out a nice pretty string when assigned to a scalar variable rather than an array.
$month += 1; might be easier than creating the array lookup table @month. And a nice shortcut when you do need that is my @month = 1..12;
Your AM/PM logic is really weird. Try:
my $ap= $hour>11 ? "PM" : "AM"; $hour = $hour % 12; $hour = $hour || 12;
sprintf is your friend. You can lose all the "zero padding" code and do this:
$date = sprintf '%3s:%02d:%02d:%4d', @days[$wday], $mday, $mon, $milly +ear; $time = sprintf '%02d:%02d:%02d:%2s:%11s', $hour, $min, $sec, $ap, $da +te;
Sure, it is all nitpicky stuff but once you look at it, ain't Perl cool?
--
$you = new YOU;
honk() if $you->love(perl)
In reply to Re: help with time stamp
by extremely
in thread help with time stamp
by tanger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |