Member since
10-13-2020
2
Posts
0
Kudos Received
1
Solution
My Accepted Solutions
Title | Views | Posted |
---|---|---|
1714 | 10-16-2020 01:53 AM |
10-16-2020
01:53 AM
After I have not been able to find a solution that would be easy to implement inside of NiFi, I've written a small perl (yuk) script that can be used to adjust timestamps in a CSV file to be in ISO8601 format. Maybe it is useful to someone else: #!/bin/perl -w
# This perl script adds timezone information to timestamps without a
# timezone. All timestamps in the input file that follow the format
# "YYYY-MM-DD HH:MM:SS" are converted to ISO8601 timestamps.
use strict;
use DateTime::Format::Strptime;
my $time_zone = 'Europe/Amsterdam';
my $parser = DateTime::Format::Strptime->new(
pattern => '%Y-%m-%d %T',
time_zone => $time_zone
);
my $printer = DateTime::Format::Strptime->new(
pattern => '%FT%T%z',
time_zone => $time_zone
);
while (<>) {
s/(?<=")(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)(?=")/
my $dt = $parser->parse_datetime($1);
$printer->format_datetime($dt);
/ge;
print;
}
... View more