Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Date Question

Status
Not open for further replies.

MMIMadness

Technical User
Feb 10, 2004
50
0
0
GB
Just begining to learn perl, and i have come across a small and probably a simple problem which i can't find an answer in the book i've got.

The problem is this. I need to reformat the output of the 'localtime' function to display it in the format dd/mm/yy hh:mm:ss (the english date and time format)

If anyone could help i would be grateful.

Thanks,
MMIMadness
 
[tt]#!/usr/bin/perl

($seconds, $minutes, $hour, $dayOfMonth, $month, $year, $dayOfWeek, $dayOfYear) = localtime(time);

$month++;
$year += 1900;

$month = sprintf("%02d", $month);
$year = substr($year, 2, 2);
$hour = sprintf("%02d", $hour);
$minutes = sprintf("%02d", $minutes);
$seconds = sprintf("%02d", $seconds);

print "$dayOfMonth/$month/$year $hour:$minutes:$seconds\n";[/tt]



Kind Regards
Duncan
 
If you are familiar with Unix date <format> , you can use the Date::Format module....

Code:
use Date::Format;
print time2str("%c", time);

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top