Perl String Date Formating

POB

POB

Soldato
Joined
27 May 2003
Posts
5,948
Location
Its a Small World
Having to use Perl for the first time to create example access to a webservice I have made in .Net.

If I have a string like this:

2009-11-19 21:01

I want to only display the time part in 12 hour format so it would become:

9:01 pm.

I'm being incrediably thick and can't work this out after googling.:confused:

Is there a function for formating strings directly?
 
Having to use Perl for the first time to create example access to a webservice I have made in .Net.

If I have a string like this:

2009-11-19 21:01

I want to only display the time part in 12 hour format so it would become:

9:01 pm.

I'm being incrediably thick and can't work this out after googling.:confused:

Is there a function for formating strings directly?
There probably is some date utils in something like time::localtime or something else from CPAN but:


my $date = "2009-11-19 21:01";
#my $date = "2009-11-19 11:01";
my $hr;
my $min;
if($date =~ /....\-..\-..\s(..)\:(..)/){
$hr = $1;

$min = $2;

}


if(($hr-12) >= 0){
$hr = $hr -12;

print "$hr : $min PM\n";
}else{


print "$hr:$min AM\n";
}


Seems to work here
 
Last edited:
Back
Top Bottom