I hasten to point out that just because your server is not in your timezone, it does not mean that it "cannot be relied upon to be accurate". But I know what you mean :-)

All you need to do is find out how many hours you are behind GMT, and substract that from localtime. Try this (untested):

my $time = localtime; my $hours_behind_gmt = 4; # localtime is in seconds, hence we need to get hours --> seconds my $time_in_my_timezone = localtime - ($hours_behind_gmt * 60 * 60); print scalar localtime($time_in_my_timezone);
Beware of the main caveat of dealing with different timezones: Daylight Savings Time. If your server is based in England, during the summer it will not use GMT--it will use BST (British Summer Time) instead. So beware.

For doing fancy operations with dates, you might like to use the Date::Calc module on CPAN. Finally, in future, please do a bit of research yourself. This is quite a basic question and the answer could probably be found with a bit of hacking and Google-ing. If you have done research, give us the code you've already got (even if you think it's bad). People are more inclined to help if you seem to be making a real effort yourself.


In reply to Re: Date and Time by SuperCruncher
in thread Date and Time by arrow

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.