Getting Midnight in the UNIX Epoch from Perl
The calculation needed to be done on the backend on the server, which is written in Perl. This page had a suggestion how to get the number of seconds so far elapsed in the day, which could easily be modified to instead give me the number of seconds remaining. Problem: I want to calculate on the basis of the local time zone not UTC/GMT. Thankfully, using Perl’s
DateTime object, that isn’t difficult:
use DateTime; my $tomorrow = DateTime->now(time_zone => $timeZone); my $secs = ((23 - $tomorrow->hour) * 3600) + ((59 - $tomorrow->min) * 60) + (59 - $tomorrow->sec); $tomorrow->add( seconds => ($secs + 1) ); my $tomorrowStarts = $tomorrow->epoch;
With that little code snippet,
$tomorrowStarts will return the first second of tomorrow located to
$timeZone and relative to the Epoch.
Start the Conversation