I was previously unaware of the strftime routine, however after testing it, I found that my $time = strftime("%Y-%m-%d %I:%M:%S %p", localtime()); worked the way I wanted. %T didn't seem to output anything, but I guess it is not support under Windows. Either way, I wanted to display in 12-hour mode.
I noticed that the snippet above is not really correct. In the test for $hour > 12, there should also be a test for $sec > 0 to be as complete as possible. So the test should be if($hour > 12 && $sec > 0).
sub recordTime {
use POSIX qw(strftime);
my $time = strftime("%Y-%m-%d %T %p", localtime());
open(TIME, ">>path/to/a/text/file.txt")
or die "Could not open file.txt to append record time: " . $!;
print TIME $time;
close(TIME);
return $time;
}
my $time = strftime("%Y-%m-%d %I:%M:%S %p", localtime());
worked the way I wanted. %T didn't seem to output anything, but I guess it is not support under Windows. Either way, I wanted to display in 12-hour mode.
I noticed that the snippet above is not really correct. In the test for $hour > 12, there should also be a test for $sec > 0 to be as complete as possible. So the test should be if($hour > 12 && $sec > 0).