How do we convert TimeZone from say UTC to America/New_York in NiFi using JavaScript in ExecuteScript processor.
More information:
I know we can do it in UpdateRecord processor which I've achieved already. But the file is too big (20GB+) and I am doing some pre-processing in ExecuteScript processor, I don't want to re-iterate the entire file all over again. Currently, it is taking 18+ hours to process a single file. Implementing the timezone conversion in ExecuteScript, I think will significantly reduce the processing time.
Exact point where I am currently in:
I'm currently unable to import and create Java objects like SimpleDateFormat
The Java code that I am trying to implement in NiFi (by converting it to JavaScript) is as below:
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class HelloWorld {
public void convertDateTimeZone() throws Exception{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
TimeZone utcZone = TimeZone.getTimeZone("UTC");
String dateInString = "1982/01/10 10:20:56";
sdf.setTimeZone(utcZone);
Date utcDate = sdf.parse(dateInString); // Create a new Date object
System.out.println(sdf.format(utcDate));
SimpleDateFormat nysdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
TimeZone newyorkZone = TimeZone.getTimeZone("America/New_York");
nysdf.setTimeZone(newyorkZone);
System.out.println(nysdf.format(utcDate));
}
}