in reply to remote perlscript
$ampm = 'AM'; if ($hour >= 12) { $hour -= 12; $ampm = 'PM'; }
Also, when you are constructing your $datetime string you could construct the whole thing in one go with the sprintf. Note that %02d will do the same thing here as %2.2d.
$datetime = sprintf '%d:%02d:%02d %s, %s, %s %d, %d', $hour, $min, $sec, $ampm, $thisday, $thismon, $mday, $year + 1900;
This looks a little clearer to my eye, particularly the format string which makes it much easier to visualise what the $datetime string will look like.
I hope this is of use.
Cheers,
JohnGG
Update: It occurs to me that 00:23 on a 24-hour clock is 12:23AM, not 0:23AM and 12:23 on a 24-hour clock is 12:23PM, not 0:23PM so revised code should in fact be
$ampm = 'AM'; if ($hour >= 12) { $hour -= 12; $ampm = 'PM'; } $hour += 12 unless $hour;
|
|---|