For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2008 > how to get timezone in perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to get timezone in perl
Yue Chen

2008-01-18, 7:02 pm

Greetings, perl fans

I am about to translate a bash script into perl. In bash script, it
uses "date +%Z" command to get current timezone on local host.
However, I don't want to redirect this output into a variable, since
the perl script will even going to be run on windows. Is there a
module to get such info?

I have tried "Time::Timezone" module. However, it print nothing from
tz2zone. Is there any thing wrong?
Chas. Owens

2008-01-18, 7:02 pm

On Jan 18, 2008 6:47 AM, Yue Chen <godsarmycy@gmail.com> wrote:
> Greetings, perl fans
>
> I am about to translate a bash script into perl. In bash script, it
> uses "date +%Z" command to get current timezone on local host.
> However, I don't want to redirect this output into a variable, since
> the perl script will even going to be run on windows. Is there a
> module to get such info?

snip

Get it from the same source that the date command gets it from: the
POSIX function strftime.

#!/usr/bin/perl

use strict;
use warnings;
use POSIX;

print strftime("%Z", localtime()), "\n";
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com