You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by "Beutel, Maximilian " <ma...@credit-suisse.com> on 2019/02/22 08:43:04 UTC

Converting string timestamp to date using expression language

Hello!

I have  a JSON file like so:

{"PROJECT_KEY":"XYZ ","LAST_METRIC_DATE":"1550648697"}

I put this into EvaluateJsonPath and create the following attributes:

                Attribute:            lastMetricDate
JSON path:          $.LAST_METRIC_DATE

Which works, the file gets an attribute lastMetricDate which equals 1550648697

Then in the next InvokeHttp processor I need to use this attribute as a date however, and here I have trouble with the expression language. Because in the URL field when I use when I use:

                http://example.com/?since=${lastMetricDate:toNumber():format("yyyy-MM-dd'T'HH:mm:dd'+0800'", "Asia/Singapore")}

I get "?since=1970-01-01 ..."

I also tried

                ${lastMetricDate:format("yyyy-MM-dd'T'HH:mm:dd'+0800'", "Asia/Singapore")}

But same result.

Is there any way I can tell Nifi that this is a UNIX timestap that should be formattable using the "format(...)" function.

Thanks!

Max

=============================================================================== 
Please access the attached hyperlink for an important electronic communications disclaimer: 
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
=============================================================================== 

Re: Converting string timestamp to date using expression language

Posted by FABIAN HUTIN <fa...@adeo.com>.
Hey Maximilian,


It seems like format operator expects your timestamp to be a 13 digits integer.

I have tried with 1550648697000, and the output seems correct.

Also watch out, it seem that your format is incorrect,  format("yyyy-MM-dd'T'HH:mm:dd' [...]")


Thanks,


Fabian HUTIN

________________________________
From: Beutel, Maximilian <ma...@credit-suisse.com>
Sent: Friday, February 22, 2019 9:43:04 AM
To: users@nifi.apache.org
Subject: Converting string timestamp to date using expression language


Hello!



I have  a JSON file like so:



{"PROJECT_KEY":"XYZ ","LAST_METRIC_DATE":"1550648697"}



I put this into EvaluateJsonPath and create the following attributes:



                Attribute:            lastMetricDate

JSON path:          $.LAST_METRIC_DATE



Which works, the file gets an attribute lastMetricDate which equals 1550648697



Then in the next InvokeHttp processor I need to use this attribute as a date however, and here I have trouble with the expression language. Because in the URL field when I use when I use:



                http://example.com/?since=${lastMetricDate:toNumber():format("yyyy-MM-dd'T'HH:mm:dd'+0800'", "Asia/Singapore")}



I get “?since=1970-01-01 …”



I also tried



                ${lastMetricDate:format("yyyy-MM-dd'T'HH:mm:dd'+0800'", "Asia/Singapore")}



But same result.



Is there any way I can tell Nifi that this is a UNIX timestap that should be formattable using the “format(…)” function.



Thanks!



Max





==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================