We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a .csv file that has time stamps in the format HH:MM:SS.MS. Example below:
Time,Z-axis,Y-axis,X-axis,Battery,∞Celsius,EDA(uS),Event
---------------------------------------------------------
12:00:45.000,-0.100,-0.060,1.080,-1,19.100,0.000,0
12:00:45.125,-0.090,-0.060,1.080,-1,19.100,0.002,0
12:00:45.250,-0.100,-0.060,1.080,-1,19.100,0.000,0
12:00:45.375,-0.090,-0.060,1.090,-1,19.100,0.000,0
12:00:45.500,-0.100,-0.060,1.080,-1,19.100,0.000,0
12:00:45.625,-0.090,-0.060,1.080,-1,19.100,0.000,0
I want to be able to read the data in each row/row at user-specified intervals as integers. However, currently the only way I can see to parse the time stamp is as a string. Can anyone help me convert it to an integer?
Answers
Which part of this is giving you trouble?
Can you read the file in line by line? If not, post an MCVE that shows what you've tried for reading the file in. Note that this shouldn't include any of the date parsing data, as that's a separate problem.
If you can read the file in and are just having trouble parsing the date, then post an MCVE showing what you've tried for parsing the date, without any of the file reading logic, since that's a separate problem. Just hardcode a date String and try to print out its parsed value.
What exactly do you mean when you say you want to convert the timestamp to an integer? What should that integer represent? The unix timestamp? Just the hour? Something else? Again, MCVEs go a long way.
Take a look at SimpleDateFormat.
How about a simpler customized TimeStamp class? O:-)
An even more complete version. It's sort()-ready and got other tricks too: :-bd
http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#sort-java.lang.Object:A-
http://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#sort-java.util.List-
Another variation. This time the TimeStamp class is immutable: (*)
http://en.wikipedia.org/wiki/Reinventing_the_wheel
Tried to run your code, got an ArrayIndexOutOfBoundsException (1) on line 44.
I knew I shoulda used splitTokens() instead of just split()! b-(
Checking out for a dot only isn't enough! Some locales use comma instead! =:)
It's all fixed now:
, int(splitTokens(nf(f[2], 0, 3), ".,")[1]));
:-B