A few notes:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.