Search code examples
datetimeapache-nifiutcunix-timestamp

Nifi convert UTC to unix time


I have a flowfile attribute which is a UTC datetime in the format of yyyy-MM-dd HH:mm:ss.SSS

I need to convert this to a unix timestamp.

How can this be done? I know its possible to convert Unix to the above format using Jolt:

"time": "${time:format('yyyy-MM-dd HH:mm:ss.SSS')}"

however, im not sure how to do this in reverse?


Solution

  • Working with attributes in this way uses the NiFi Expression Langauge (not Jolt).

    See the docs here https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

    ${time:format('yyyy-MM-dd HH:mm:ss.SSS')}
    

    Uses Expression Language to format the time attribute to the given SimpleDateFormat string.

    ${time:toNumber()}
    

    Uses Expression Language to convert the given Date object to Epoch Millis.

    https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#tonumber