Hi,

Altering your $ENV{TZ}, for a very quick hack could do. A local $ENV{TZ} = 'EET' # EET? is a bit better.

But beware (know what you do)! This is potentially dangerous, if you use qx// or [system]() calls, require other perl scripts/use modules, do IPC (interact with other running processes), have changing configuration (see below), etc.

In a production script/environment you'll want to use a Date/Time manipulation module, like the excellent Date::Manip or Date::Calc. These will do what you need (and more), safely with regard to daylight saving times and/or configuration changes. Imagine what happens if your servers' sysop one day decides he'd switch his servers to use UTC as their RTC's timezone. These modules will return the correct date, simply adding the n hours offset will fail in such a case...

Times are just data. Operate on it. If you want to know what time it is in Zimbabwe, you'd calculate the difference to your local time -- you wouldn't reset your wristwatch (i. e. change your configuration) to see what the time would be (I hope ;)...

Hope this helps a bit,

so long,
Flexx


In reply to Re: Localtime() or gmtime() by Flexx
in thread Localtime() or gmtime() by NetStorm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.