user2380503
user2380503

Reputation: 21

strftime '%z', (localtime) is not working as expected in solaris machines

I tried this code in linux machines,

my $sysdate = strftime "%Y%m%d%T", (localtime);    
my $daylight_saving_time = strftime '%z', (localtime);

i get below output,

sysdate = 2013051402:12:02    
daylight_saving_time = -0400

I tried same in solaries machines, i got this

sysdate = 2013051402:12:02
daylight_saving_time = %z

Anyone know the change to be done to get the daylight saving in solaries machines.

Thanks in Advance.

Upvotes: 1

Views: 874

Answers (2)

jim mcnamara
jim mcnamara

Reputation: 16399

The issue is that POSIX::strftime just calls your system's strftime(3), so you get whatever that is - or - is not. %z is not part of the POSIX.1 standard and is not consistent across systems. On other older versions of OSes, like HPUX, %z, is the same as %Z (time zone name). This is only for older versions.

On Solaris 8, 9 strftime does not support %z - with Solaris 10 it does.

This holds on more moderns versions Solaris 10 & Solaris 11:

%z Replaced by offset from UTC in ISO 8601:2000 standard format (+hhmm or -hhmm), or by no characters if no time zone is deter- minable. For example, "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich). If tm_isdst is zero, the standard time off- set is used. If tm_isdst is greater than zero, the daylight sav- ings time offset if used. If tm_isdst is negative, no characters are returned.

So, this a C library function issue, perl sits on top of those libraries. I do not have a workaround.

Upvotes: 1

user1126070
user1126070

Reputation: 5069

Maybe the Date::Manip::TZ works on Solaris:

   use Date::Manip::TZ;
   my $tz = new Date::Manip::TZ;
   say "tz: $tz";

Upvotes: 0

Related Questions