How to convert unix timestamp to datetime in Apache NiFi

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to convert unix timestamp to datetime in Apache NiFi

Puspak
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/
Reply | Threaded
Open this post in threaded view
|

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

Mark Payne
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 <[hidden email]<mailto:[hidden email]>> 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/

Reply | Threaded
Open this post in threaded view
|

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

Puspak
Thanks for the suggestion



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