I have needed to put the date and time in a specefic format for the ARS helpdesk system in order to move the call status into a resolved state.
The format ARS accepts is mm/dd/yyyy hh:mm:ss AM/PM
The issue here is AM/PM.
I have done this but was wondering if there is a slicker way of doing it.
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);
}
This works, but
I'm sure the gurus have this in two or three lines as opposed to any many as mine.
-----
Of all the things I've lost in my life, its my mind I miss the most.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.