in reply to Convert GMT timestamp to EST/EDT
Despite that you're asking for "without using new additional Perl Libraries", I'd suggest using the Date-Manip library.
There's one complication. Date-Manip won't handle the fractional seconds for you, other than ignoring it when parsing a date. If you don't need to keep the fractional seconds, then this should work:
use warnings; use 5.016; use Date::Manip::Date; my$db = Date:: Manip::Date->new(undef, ["setdate" => "now,utc"]); # parse as UTC date +s while (<>) { chomp; my($datestr, $count) = split /,/; my$d = $db->new; if (my $e = $d->parse($datestr)) { warn qq(cannot parse date: $datestr); } else { $d->convert("America/New_York"); say $d->printf("%Y%m%d-%H:%M:%S %Z"); # print in similar forma +t, but with timezone name } }
If you also have to handle the fractional seconds, then either use a different module that handles them, or copy the fractional seconds by hand, like this.
use warnings; use 5.016; use Date::Manip::Date; my$db = Date::Manip::Date->new(undef, [q(setdate) => q(now,utc)]); while (<>) { /^([-0-9:]{17})(\.[0-9]{3}),(.*)/ or die qq(cannot parse input lin +e); my($datestr, $frac, $count) = ($1, $2, $3); my$d = $db->new; if (my $e = $d->parse($datestr)) { warn qq(cannot parse date: $datestr); } else { $d->convert(q(America/New_York)); say $d->printf(q(%Y%m%d-%H:%M:%S)) . $frac . $d->printf(q( %Z) +); } }
Output from the latter code follows.
20150619-13:30:43.616 EDT 20150619-13:30:33.442 EDT 20150619-13:30:40.376 EDT 20150619-13:30:38.863 EDT 20150619-13:30:56.936 EDT 20150619-13:30:34.952 EDT 20150619-13:30:45.889 EDT 20150619-13:30:53.940 EDT 20150619-13:30:51.154 EDT 20150619-13:30:48.699 EDT
Update: for similar questions, see also GMT to PST format
|
|---|