Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Converting an attribute epoch timestamp to datetime

avatar
Explorer

Searched for this and have not found the solution or I'm having the stupids.

 

From an API I get a JSON file that I then use the EvaluateJsonPath processor to add an attribute to the flow file.

 

One of these attributes is "date_posted" which is in epoch, seconds since 1st Jan 1970.

nifi_attr1.JPG

 

I need to convert this into a date format so using the UpdateAttribute processor.
nifi_attr1.JPG

 

I have tried these

${date_posted:multiply(1000):format("yyyy-MM-dd HH:mm:ss","GMT")}

${date_posted:toNumber():multiply(1000):format("yyyy-MM-dd HH:mm:ss","GMT")}

 

and even for testing just these:

${date_posted:toNumber()}

${date_postedmultiply(1000)}

${date_posted:toNumber():multiply(1000)}

 

Yet afterwards my date_posted attribute ends up with an empty string:

nifi_attr1.JPG

What am I missing?

1 ACCEPTED SOLUTION

avatar
Explorer

Hi Everyone, sorry about the confusion. It was late and I was actually looking at the wrong flow file output: i.e. looking at the top one on the list (oldest) instead of the bottom one on the list (newest).

 

@stevenmatison thank you for your reply and effort in making a template.

View solution in original post

2 REPLIES 2

avatar
Super Guru

@Tokolosk the solution you need is:

 

${date_posted:format('MM-dd-yyyy hh:mm:ss') }
${date_posted:multiply(1000):format('MM-dd-yyyy hh:mm:ss') }

Of course you can experiment with different format...

 

 

I created a test in a template I use (Working With Timestamps) where I set date_posted to your string value, then 2 conversion tests:

 

Screen Shot 2020-09-02 at 4.31.50 PM.png

 

Screen Shot 2020-09-02 at 4.35.19 PM.png

Screen Shot 2020-09-02 at 4.31.34 PM.png

 

If you are getting empty values, then I suspect you have an issue with ${date_posted} not the expression language.  Maybe also take a look at using a different attribute name for formatted timestamp. 

 

Hope this helps...

 

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  

 

Thanks,


Steven @ DFHZ

avatar
Explorer

Hi Everyone, sorry about the confusion. It was late and I was actually looking at the wrong flow file output: i.e. looking at the top one on the list (oldest) instead of the bottom one on the list (newest).

 

@stevenmatison thank you for your reply and effort in making a template.