If you don't want to use Date::Format and don't care that your code might be 'internationalised', here's a snippet of code that I continually reuse:
sub library_todayis { my ($time)=@_; if ($time<1) { $time=time(); } my @months=qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!; my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = loca +ltime($time); if ($day<10) { $day="0".$day; } if ($hour<10) { $hour="0".$hour; } if ($min<10) { $min="0".$min; } if ($sec<10) { $sec="0".$sec; } $year = $year + 1900; return ("$day $months[$mon] $year $hour:$min"); }
Pass it the timestamp you want converting (or leave blank for the current time), and in return you'll get something like 13 Feb 2002 18:48 in your current timezone.

Update: Thanks to little, for a 'duh! why are you doing it like that?' here's a shortened version doing it the slightly better way using sprintf:

sub library_todayis { my $time=shift || time(); my @months=qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!; my ($sec,$min,$hour,$day,$mon,$year)=localtime($time); $year+=1900;$mon++; return sprintf("%02d $months[$mon] $year %02d:%02d",$day,$hour,$min); }
Which, I have to confess is a lot better looking and probably a bit faster (although I haven't benchmarked it)

In reply to Re: Re: date by beebware
in thread Year shows as 20102 in date by Anonymous Monk

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.