You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by Puspak <pu...@gmail.com> on 2019/04/17 13:18:57 UTC

How to convert unix timestamp to datetime in Apache NiFi

i have an attribute named "actualarrivaltime"  and value as
1555501600(unixmiliseconds)
i want to covert the same to a date fromat .

i tried ${actualarrivaltime : format('MM/dd/yyyy HH:mm:ss.SSS')}, but it
gives me wrong result .

i am getting the value after the conversion is actualarrivaltime :01/01/1970
05:30:00.000



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/

Re: How to convert unix timestamp to datetime in Apache NiFi

Posted by Puspak <pu...@gmail.com>.
Thanks for the suggestion 



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/

Re: How to convert unix timestamp to datetime in Apache NiFi

Posted by Mark Payne <ma...@hotmail.com>.
Puspak,

For that timestamp given, 01/01/1970 05:30:00.000 is the correct time.
I suspect, though, that what you have there is not Unix milliseconds but rather Unix seconds.
Try multiplying that by 1000: ${actualarrivaltime:multiply(1000):format("MM/dd/yyyy HH:mm:ss.SSS")}

If we use this simple Java program:


public static void main(final String[] args) throws Throwable {
    final long timestamp = 1555501600L;
    System.out.println("Timestamp: " + new Date(timestamp));
    System.out.println("Timestamp * 1000: " + new Date(timestamp * 1000L));
}

We get the output (in EDT):

Timestamp: Sun Jan 18 19:05:01 EST 1970
Timestamp * 1000: Wed Apr 17 07:46:40 EDT 2019

Thanks
-Mark


On Apr 17, 2019, at 9:18 AM, Puspak <pu...@gmail.com>> wrote:

i have an attribute named "actualarrivaltime"  and value as
1555501600(unixmiliseconds)
i want to covert the same to a date fromat .

i tried ${actualarrivaltime : format('MM/dd/yyyy HH:mm:ss.SSS')}, but it
gives me wrong result .

i am getting the value after the conversion is actualarrivaltime :01/01/1970
05:30:00.000



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/