Hi,

I have a list of dates in local standard time that I want to convert to local time.

I came up with this, but I guess there's some smarter way...

Thanks



use strict; use DateTime::Duration; use DateTime; # These are local standard times in Europe/Rome, i.e. always UTC+0100 my @dates = ( [2020,12,2,1,0], [2021,7,2,1,0] ); my $timezone = '+0100'; # This is the duration to be added to go from LST to UTC my $seconds = -($timezone/100) * 3600; my $dur = DateTime::Duration->new( years => 0, months => 0, weeks => 0, days => 0, hours => 0, minutes => 0, seconds => $seconds, nanoseconds => 0 ); for my $date (@dates) { my $dt = DateTime->new( year => => $date->[0], month => $date->[1], day => $date->[2], hour => $date->[3], minute => $date->[4], second => 0, nanosecond => 0, time_zone => 'UTC' ); $dt->add($dur); # This is a DateTime object in LST print "LST: ",join("-",@{$date}),"\n"; print "UTC: ",$dt->set_time_zone("UTC"),"\n"; print "LT: ",$dt->set_time_zone("Europe/Rome"),"\n"; }

In reply to Convert LST dates to LT dates by Anonymous Monk

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.