perl quick date convert

A

asdfq213rr23we

Hi

Whats the smoothest way of converting the date string "2004-10-10
12:14:23" to "Tue, 10 Oct 2004 12:14:23"?

Thanks !
M
 
T

Tony Curtis

On 1 Feb 2005 15:52:24 -0800,
Hi Whats the smoothest way of converting the date string
"2004-10-10 12:14:23" to "Tue, 10 Oct 2004 12:14:23"?

Depends on hat your criteria for "smooth" are, but I'd
probably use UnixDate() from Date::Manip.

(However, are you sure 10/10 is Tuesday?)

hth
t
 
G

Gunnar Hjalmarsson

Tony said:
Depends on hat your criteria for "smooth" are, but I'd
probably use UnixDate() from Date::Manip.

Personally I would stick to the standard module Time::Local.

use Time::Local 'timelocal';
my @t = split /\D+/, '2004-10-10 12:14:23';
printf '%s, % 2s %s %d %s', ( split ' ', scalar localtime
timelocal reverse shift(@t)-1900, shift(@t)-1, @t )[0,2,1,4,3];

To the OP: Why do you want to convert *from* a universally readable and
ISO compliant format?
 
T

Tony Curtis

Personally I would stick to the standard module Time::Local.
use Time::Local 'timelocal'; my @t = split /\D+/,
'2004-10-10 12:14:23'; printf '%s, % 2s %s %d %s', ( split '
', scalar localtime timelocal reverse shift(@t)-1900,
shift(@t)-1, @t )[0,2,1,4,3];

Well, of course each() to his own but

use Date::Manip qw(UnixDate);

my $date = '2004-10-10 12:14:23';
my $now = UnixDate($date, '%a, %d %b %Y %H:%M:%S');

print "$now\n";

looks rather less opaque to me. As always it depends on what
problem you're trying to solve.
 
D

D. Marxsen

Hi

Whats the smoothest way of converting the date string "2004-10-10
12:14:23" to "Tue, 10 Oct 2004 12:14:23"?

I use Date::Calc

Dunno if it is the smoothest way - but it very simple to use and it has a
huge set of functions.

Cheers,
Detlef.
 
A

asdfq213rr23we

Thanks all! Good question, I needed this to convert the date to rss
format..
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top