There is a new KNIME forum. You can still browse and read content from our old forum but if you want to create new posts or join ongoing discussions, please visit our new KNIME forum: https://forum.knime.com

Convert Unix-like date/time (elapsed time from 1904 01 01 in second) into Knime date/time format

Member for

4 years 3 months N700A

Hello, I just started using Knime and a newbie.
I have been analyzing time-series data on other data-processing software like Igor-Pro.
The date/time format on Igor-Pro is elapased time from 1904 1/1 in second. I tried to convert it to Knime date/time format using Date/Time Shift node since I found quite similar post on this forum.

By taking Shift value from the time/date column(elapsed-time) and set Date Reference as 1904 Jan-1, I expected it would work fine, but it did not.

I found the Date/Time Shift mode only accept Interger value, not double precision elapsed time like one I have. By converting the data type into integer, time-precision in millisecond  will be lost (although Knime date/time has millisecond time resolution).

How can I do this simple conversion with a simple way?

Thank you very much in advance!

 

Comments
Thu, 06/02/2016 - 04:11

Member for

4 years 5 months

marco_ghislanzoni

It might be a bit of a workaround, but I would use a Java Snippet (simple) Node with the code below to convert the elapsed time (Epoch) to a date/time string, then use the String to Date/Time node to convert it to KNIME date/time.

Epoch is a double, where the decimal part represents the milliseconds.

long unixdate = (long) Math.round($Epoch$ * 1000);
DateFormat formatter = new SimpleDateFormat("d MMM yyyy HH:mm:ss.SSS");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(unixdate);
return formatter.format(calendar.getTime());

Set the return type of the Java Snippet (simple) node to String. 

In the String to Date/Time node use exactly the same string from the formatter above in the "date format" configuration field.

This should do the trick.

Cheers,
Marco.

Thu, 06/30/2016 - 12:26

Member for

4 years 11 months

ferry.abt

Hello N700A,

You can use the Date/Time Shift node, but you need to transform your time:
Instead of using doubles, use the Math Formula node and multiply your number with 1000. By this you will get the milliseconds passed since your start-date. Set the output of the Math Formula to be an Integer and in the Date/Time Shift set the granularity to Seconds.

Best,
Ferry

Fri, 06/02/2017 - 09:53

Member for

4 years 2 months

aherzberg

Hi marco_ghislanzoni & ferry.abt, 

Great! Thanks so much for helping me out! :)

Best, Andy

Wed, 07/26/2017 - 04:22

Member for

10 years 4 months

Iris

das ist der text im inhalt