[
https://issues.apache.org/jira/browse/NIFI-3524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15879867#comment-15879867
]
Joseph Witt commented on NIFI-3524:
-----------------------------------
The following code helped me to believe that the existing JIRA does solve the
core problem and shows that the behavior of formatting by default uses the
local jvm timezone and requires explicit override (not from the format string
but explicitly on the object). I think what we need to do is improve
documentation and provide examples around usage but the existing JIRA appears
legit to me. Admittedly this was pretty easy to get confused and wrapped
around the axle on. I'm not 100% clear but it makes a lot more sense now than
it did during the e-mail thread.
{code:title=FunDates.java|borderStyle=solid}
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class FunDates {
public static void main(final String[] args) {
final String simpleFormatPattern = "yyyy-MM-dd'T'HH:mm:ssXXX";
final String simpleFormatPatternZ = "yyyy-MM-dd'T'HH:mm:ss'Z'";
final String dateTimeStr = "2017-02-22T23:01:23+11:00";
final TimeZone tz = TimeZone.getTimeZone("UTC");
final SimpleDateFormat format = new
SimpleDateFormat(simpleFormatPattern);
final SimpleDateFormat formatZ = new
SimpleDateFormat(simpleFormatPatternZ);
try {
format.setTimeZone(TimeZone.getTimeZone("UTC"));
formatZ.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println("Date Time String Received: " + dateTimeStr);
System.out.println("TimeZone Set on Formatter: " + tz);
System.out.println("Simple Format Pattern: " + simpleFormatPattern);
final Date date = format.parse(dateTimeStr);
System.out.println("Date after parsing: " + date);
System.out.println("Date to epoch millis: " + date.getTime());
System.out.println("Date formatted as Zulu time: " +
formatZ.format(date));
} catch (Exception ex) {
System.out.println("Dates aren't fun ");
ex.printStackTrace();
}
}
}
{code}
> EL DateTime objects should be TZ aware
> --------------------------------------
>
> Key: NIFI-3524
> URL: https://issues.apache.org/jira/browse/NIFI-3524
> Project: Apache NiFi
> Issue Type: Bug
> Reporter: Andre F de Miranda
> Priority: Critical
>
> As highlighted by NIFI-2908 and subsequent email threads, the use of DateTime
> objects with EL seems to be affected by java.util.Date infamous timezone free
> objects.
> With the shift into Java 8, we should probably refactor EL to use java.time.*
> classes as JSR-310 introduce plenty of TZ awareness to handling of Date and
> Time in Java.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)