- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Date with now() in a specific format in a specific timezone
- Labels:
-
Apache NiFi
Created ‎06-11-2024 12:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In an UpdateAttribute processor I am trying to get the date of yesterday, at midnight in the CET timezone then have it transformed to a specific format in UTC.
What I did was :
${now():minus(86400000):format('yyyy-MM-dd\'T\'00:00:00\'Z\'' , 'CET')}
but this still gave me the time at midnight in UTC and not CET.
What I want basically is if today is 2024-06-11 I want to get : 2024-06-10T22:00:00Z
also, there is this issue with the CEST , If I specify CET is CEST not considered ?
I just don't want to have to change my processor every 6 months a year and have something that works no matter what
Created ‎06-11-2024 02:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ideally, it should return the current date minus 24 hours and convert it to a specific time zone. Please check your server time.
CET: ${now():toNumber():minus(86400000):format('yyyy-MM-dd HH:mm:ss', 'CET')}
GMT: ${now():toNumber():minus(86400000):format('yyyy-MM-dd HH:mm:ss', 'GMT')}
Midnight CET: ${now():toNumber():minus(86400000):format('yyyy-MM-dd', 'CET'):append(' 00:00:00')}
Thanks
Created on ‎06-11-2024 06:55 AM - edited ‎06-11-2024 06:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@ranie
I see a couple issues with your NiFi Expression Language (NEL) statement:
- I see some formatting issues in your java simple formatter string: 'yyyy-MM-dd\'T\'00:00:00\'Z\'. Your single and double quotes are not balanced.
- You are using the function "format ()" to change the timezone, but you could also use the "formatInstant()" function.
- You are missing the "toNumber()" function to convert the date string to a number before trying to apply a mathematically computation to it.
The Now() function will return the date current system time as the NiFi service sees it.
example: my NiFi server uses UTC timezone:
The toNumber() function will provide the current date and time as a number of milliseconds since midnight Jan 1st, 1970 GMT. This number will always be a GMT value.
The formatInstant() function will allow you to take a GMT time or a Java formatted date string and reformat it for a different timezone.
Taking above feedback into consideration, the following NEL statement should work for you.
${now():toNumber():minus(86400000):formatInstant("yyyy-MM-dd'T'HH:mm:ss 'Z'", "CET")}
Pay close attention to your use of single and double quotes.
Please help our community thrive. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.
Thank you,
Matt
