Date format in perl

M

MES

I want a quick way to convert a unix date to a date in the following format:

YYYY_MM_DD_HH_MM_SS:

I currently have $date = time

Is there an easy way to convert time to the above format?

Thanks!
 
M

Mark Clements

MES said:
I want a quick way to convert a unix date to a date in the following format:

YYYY_MM_DD_HH_MM_SS:

I currently have $date = time

Is there an easy way to convert time to the above format?

check out Date::Format, but next time you may want to check out
http://search.cpan.org before posting.

Mark
 
T

Tad McClellan

MES said:
I want a quick way to convert a unix date to a date in the following format:

YYYY_MM_DD_HH_MM_SS:

I currently have $date = time

Is there an easy way to convert time to the above format?


my $time = time;
my @parts = (localtime $time)[0..5];
$parts[5] += 1900;
$parts[4]++;
my $date = sprintf '%4d_%02d_%02d_%02d_%02d_%02d', reverse @parts;

print "$date\n";
 
G

Glenn Jackman

At 2004-09-09 12:02PM said:
I want a quick way to convert a unix date to a date in the following format:

YYYY_MM_DD_HH_MM_SS:

I currently have $date = time

Is there an easy way to convert time to the above format?

use POSIX qw(strftime);
$date = strftime "%Y_%m_%d_%H_%M_%S:", localtime;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,420
Latest member
ZitaVos505

Latest Threads

Top