Reputation: 338
I am trying to convert the date 14-JUL-16 11.37.42.649000000 AM into 07/14/2016 11:37:42 fomat
My Ni-Fi command is
${LastContactTimestamp:toDate("dd-MMM-yy hh:mm:ss.SSSSSSSSS"):format("MM/dd/yyyy HH:mm:ss")}
I am getting the error "Caused by: org.apache.nifi.attribute.expression.language.exception.IllegalAttributeException: Cannot parse attribute value as a date; date format: dd-MMM-yy hh:mm:ss.SSSXXX; attribute value: 14-JUL-16 11.37.42.649 AM"
tried to replace the Miliseconds but getting the same error
${LastContactTimestamp:replaceAll('(\.\d{3})\d*','$1'):toDate("dd-MMM-yy hh:mm:ss.SSSXXX"):format("MM/dd/yyyy HH:mm:ss")}
how do I convert into proper date format in Apache-NiFi
Upvotes: 2
Views: 1089
Reputation: 5474
I think you have to replace the colons in your first date format string with dots. Also your millisecond precision does not line up. I guess the following should do the job:
dd-MMM-yy hh.mm.ss.SSSSSSSSS aa
So putting that together your expression will look something along the lines of:
${LastContactTimestamp:toDate("ddd-MMM-yy hh.mm.ss.SSSSSSSSS aa"):format("MM/dd/yyyy HH:mm:ss")}
The available format options and their mappings can be seen in the documentation.
Currently I'm unable to fact check this in my NiFi but will do so tomorrow evening.
Upvotes: 2