Skip to content

Instantly share code, notes, and snippets.

Last active Jan 18, 2019
What would you like to do?
Convert local timestamps in text to UTC
#!/usr/bin/env perl
use strict;
use DateTime;
use Date::Parse qw(str2time);
my $pattern = qr/\d?\d:\d\d(:\d\d)?(?: ?[aApP][mM])?/;
while (<>) {
s/$pattern/utc(str2time($&), $1)/eg;
sub utc {
my($epoch, $sec) = @_;
my $utc = DateTime->from_epoch(
epoch => $epoch,
time_zone => "UTC",
$utc->strftime( defined $sec ? "%H:%M:%S" : "%H:%M" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment