#!/usr/bin/env perl use strict; use warnings; use Time::Local; use Time::Piece; my $datestr = '2017-06-19 10:07:42-0700'; print "Original date string: $datestr\n\n"; print "Using Time::Local\n"; my $time = timelocal(42, 7, 10, 19, 6, 2017); print " Epoch seconds: $time\n"; print " CORE::localtime: ", scalar CORE::localtime($time), "\n"; print "\n"; print "Using Time::Piece:\n"; print " strptime as static method:\n"; my $obj = Time::Piece->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n"; print " strptime as localtime instance method:\n"; $obj = localtime->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n"; print " strptime as gmtime instance method:\n"; $obj = gmtime->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n";