0

i have been trying to convert a string to date using

${test:toString():toDate('dd-MMM-yy HH.mm.ss.SSSSSSSSS'):format('dd-MMM-yy HH.mm.ss.SSSSSSSSS')}

my value for test attribute is like 13-MAR-20 15.50.41.396000000

when i'm using the above mentioned expression to convert the string to Date, it actually is changing the date as below:

test (input value):

13-MAR-20 15.50.41.396000000

time (output value)

18-Mar-20 05.50.41.000000000

please advise!

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • Can you test this segment by segment, and convert it to a different format e.g. `${date:toDate('dd-MMM-yy'):format('yyyy/MM/dd')}` – wp78de Mar 16 '20 at 15:51
  • java date does not support `SSSSSSSSS`. you could use only 3 digits for milliseconds `SSS` – daggett Mar 16 '20 at 16:15
  • i've tried it with 3 digits it is working good. is there a way i can get 9 digit precision on millis (in nifi) – Adithya Sajjanam Mar 16 '20 at 17:32

1 Answers1

0

I ran into a similar issue with date time encoded in ISO 8601.

The problem is, that the digits after the second are defined as fragment of a second, not milliseconds. If it has 3 digits, it equivalent to milliseconds. If more than 3, the toDate() function parse the fragment of a second as milliseconds. In your case 396000000 milliseconds = 4,58333333 days.

I solved my issue with replaceAll() by cutting digits to first 3.

${test:replaceAll('(\.[0-9]{3})([0-9]+)','$1')}

But my value was formatted as 18-06-20T05:50:41.396000000, so maybe you have to adjust the regex.

James Risner
  • 5,451
  • 11
  • 25
  • 47