Home: Perl Programming Help: Intermediate:
AIX61 Perl5.8.8.120

New User

Aug 21, 2010, 5:03 PM

Views: 984
AIX61 Perl5.8.8.120

I have the following code in my script which has been working on AIX5.3 but it started giving me wrong "hour" (localtime -5 hrs) when running on AIX61. Here is the code:

EPOCH_DATE=`date +%s`
perl -le ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime('${EPOCH_DATE}'); printf "%02d%02d%02d%02d%02d\n",$mon+1,$mday,$hour,$min,$year%100'

Appreciate any help.

Veteran / Moderator

Aug 21, 2010, 5:22 PM

Views: 981
Re: [kuldip27] AIX61 Perl5.8.8.120

The first step is to verify that the server is set to the correct datetime, preferably via ntp.

Then, use the strftime function from the POSIX module.

use POSIX qw(strftime); 

print strftime("%m%d%H%M%y", localtime);