Reputation: 1052
I'm having a bit of trouble with timezones and Perl. I have a feed that comes from the (US) east coast; my server is in central time, and the end product needs to reflect eastern time. From the feed I get times like HH:mm
(it's from a schedule and is the same for any day). So I convert this into epoch using str2time
. Now when I send the schedule to the client (a JSON) I'm sending server time. The problem I'm running is that I don't really want to my $time = time() + 3600
to add the hour from EST/EDT. My question is: can I add that hour in a different way?
Upvotes: 0
Views: 705
Reputation: 385506
use DateTime qw( );
say DateTime
->from_epoch(epoch => $epoch, time_zone => 'America/Chicago')
->strftime('%Y-%m-%d %H:%M:%S');
Upvotes: 1
Reputation: 29844
This is the Q&D or one-off "solution":
my @tvs = localtime( time );
$tvs[2]++;
my $eastern_time = POSIX::strftime( $my_format, @tvs );
That's the gist of it anyway. There are probably more complex solutions out there.
Upvotes: 1