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)