Reputation: 73
I'm trying to get the current time in perl using strftime, but it doesn't give me the time zone in the form I want. According to this: http://search.cpan.org/~dexter/POSIX-strftime-GNU-0.02/lib/POSIX/strftime/GNU.pm, %z is used for the form "-0700", and I saw some where else that %:z gives form "-07:00" which would be ideal.
But %z is giving me the timezone name, and %:z doesn't even work.
use POSIX qw/strftime/;
#This prints "2014-09-30T12:54:11-Pacific Daylight Time"
print strftime("%Y-%m-%dT%H:%M:%S-%z\n", localtime(time));
#This doesn't print anything
print strftime("%Y-%m-%dT%H:%M:%S-%:z\n", localtime(time));
#What I want: "2014-09-30T12:54:11-07:00"
Upvotes: 0
Views: 200
Reputation: 69314
POSIX::strftime uses your operating system's underlying strftime
library. So the options available to you are listed in your local manpages. As the POSIX documentation says:
Consult your system's strftime() manpage for details about these and the other arguments.
That's probably "man strftime".
I'm using Ubuntu 14.04 and I get the expected results.
$ perl -MPOSIX=strftime -E'say strftime("%z", localtime)'
+0100
You need to look closer at your local implementation of strftime
.
Upvotes: 1