[
https://issues.apache.org/jira/browse/NIFI-14620?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17956631#comment-17956631
]
Daniel Stieglitz edited comment on NIFI-14620 at 6/6/25 8:08 PM:
-----------------------------------------------------------------
[~fube1]
In NIFI 1.x {{toDate}} under the hood used {{java.text.SimpleDateFormat}} to
create the {{java.util.Date}} object and then a call to its {{toString}}
method, while in NIFI 2.x {{toDate}} uses
j{{{}ava.time.format.DateTimeFormatter{}}} to create a {{java.time.Instant}}
object which it then creates a {{java.util.Date}} object from and calls its
{{toString}} method.
When using {{java.text.SimpleDateFormat}} the timezone information was
preserved hence when {{java.util.Date}} {{toString}} was called you were able
to see the various time zones you had set. Unlike
{{{}java.text.SimpleDateFormat{}}}, {{java.time.Instant}} does not have
timezone information hence the {{java.util.Date toString}} falls back to using
the locale's where its run timezone. This is why you consistently see Sun Jun
01 00:00:00 CEST 2025 no matter what timezone you set. See NIFI-8161 for more
details.
In order to get the expected results in NIFI 2.x, you must chain three NIFI
expressions together {{{}toDate{}}}, {{toNumber}} and {{formatInstant}} along
with the syntax from {{java.time.format.DateTimeFormatter}} to get the
timestamp you desire. Please see table below for the chained expressions syntax
along with the time zones you specified. Please note this is not exactly like
your case as I ran the examples below on a machine whose timezone is UTC.
||Expression||Result||
|{{{}$\{date:toDate('yyyyMMdd'):toNumber():formatInstant('E MMM dd HH:mm:ss z
yyyy', 'UTC'){}}}}|{{Sun Jun 01 00:00:00 UTC 2025}}|
|{{{}$\{date:toDate('yyyyMMdd'):toNumber():formatInstant('E MMM dd HH:mm:ss z
yyyy', 'Europe/Kiev'){}}}}|{{Sun Jun 01 03:00:00 EEST 2025}}|
|{{{}$\{date:toDate('yyyyMMdd'):toNumber():formatInstant('E MMM dd HH:mm:ss z
yyyy', 'America/Detroit'){}}}}|{{Sat May 31 20:00:00 EDT 2025}}|
Please let us know if that satisfies your needs and whether you have any
further questions.
was (Author: JIRAUSER294662):
[~fube1]
In NIFI 1.x {{toDate}} under the hood used {{java.text.SimpleDateFormat}} to
create the {{java.util.Date}} object and then a call to its {{toString}}
method, while in NIFI 2.x {{toDate}} uses
j{{{}ava.time.format.DateTimeFormatter{}}} to create a {{java.time.Instant}}
object which it then creates a {{java.util.Date}} object from and calls its
{{toString}} method.
When using {{java.text.SimpleDateFormat}} the timezone information was
preserved hence when {{java.util.Date}} {{toString}} was called you were able
to see the various time zones you had set. Unlike
{{{}java.text.SimpleDateFormat{}}}, {{java.time.Instant}} does not have
timezone information hence the {{java.util.Date toString}} falls back to using
the locale's where its run timezone. This is why you consistently see Sun Jun
01 00:00:00 CEST 2025 no matter what timezone you set. See NIFI-8161 for more
details.
In order to get the expected results in NIFI 2.x, you must chain three NIFI
expressions together {{{}toDate{}}}, {{toNumber}} and {{formatInstant}} along
with the syntax from {{java.time.format.DateTimeFormatter}} to get the
timestamp you desire. Please see table below for the chained expressions syntax
along with the time zones you specified. Please note this is not exactly like
your case as I ran the examples below on a machine whose timezone is UTC.
||Expression||Result||
|{{{}$\{date:toDate('yyyyMMdd'):toNumber():formatInstant('E MMM dd HH:mm:ss z
yyyy', 'UTC'){}}}}|Sun Jun 01 00:00:00 UTC 2025|
|{{{}$\{date:toDate('yyyyMMdd'):toNumber():formatInstant('E MMM dd HH:mm:ss z
yyyy', 'Europe/Kiev'){}}}}|Sun Jun 01 03:00:00 EEST 2025|
|{{{}$\{date:toDate('yyyyMMdd'):toNumber():formatInstant('E MMM dd HH:mm:ss z
yyyy', 'America/Detroit'){}}}}|Sat May 31 20:00:00 EDT 2025|
Please let us know if that satisfies your needs and whether you have any
further questions.
> EL toDate() always uses local timezone
> --------------------------------------
>
> Key: NIFI-14620
> URL: https://issues.apache.org/jira/browse/NIFI-14620
> Project: Apache NiFi
> Issue Type: Bug
> Components: Core Framework
> Affects Versions: 2.4.0
> Environment: OS: RedHat 9.5
> Reporter: Beat Fuellemann
> Assignee: Daniel Stieglitz
> Priority: Major
>
> I use a parameter date "20250601". Nifi is running in CEST timezone.
> Now I need to generate a date in UTC based on the parameter "date".
> If I use UpdateAttribute Processor with
> ${date:toDate(''yyyyMMdd,'UTC')}, it generates the timestamp "Sun Jun 01
> 00:00:00 CEST 2025". I would expect "Sun Jun 01 *02:00:00* CEST 2025".
> I also already tested it with timezone "Europe/Kiev" or "America/Detroit", I
> always get "Sun Jun 01 00:00:00 CEST 2025".
> It looks, that this Nifi expression Language method "toDate" always uses the
> local timezone.
> In release 1.23.2 it was working fine.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)