Does anyone know how to use Perl to return the value of the current date/time in this format:
MM/DD/YYYY HH:MI:SS AM/PM
Does anyone know how to use Perl to return the value of the current date/time in this format:
MM/DD/YYYY HH:MI:SS AM/PM
Specifically, look at:
strftime("%x", localtime(time))
where "%x" can be any of the usual formats supplied to the standard `date` command.
HTH
Thanks. I almost have it, but I can't get the AM/PM
Here's my code:
use Time::localtime;
my $tm = localtime(time);
printf("Dateline: %02d/%02d/%04d %02d:%02d:%02d\n",
$tm->mon+1, $tm->mday, $tm->year+1900, $tm->hour, $tm->min, $tm->sec );
use Time::localtime;
my $tm = localtime(time);
if ($tm->hour lt 12) {
$junk = "AM";
} else {
$junk = "PM";
}
printf("Dateline: %02d/%02d/%04d %02d:%02d:%02d",
$tm->mon+1, $tm->mday, $tm->year+1900, $tm->hour, $tm->min, $tm->sec );
print " $junk\n";
Someone else can probably give something a bit cleaner (I haven't played with Perl in some time)
Another possibility: download the Time::Format module from search.cpan.org. It has a flexible date time formatting language that should address most if not all formatting requirements.
Documentation: