3

I have written a generic CSV file reader that I'm trying to use to read some pre-generated CSV data files. These files contain price information and a timestamp in the following format

lTid,cDealable,NAME,TIMESTAMP,BID,ASK  <--- The header

1705852073,D,EUR/USD,2011-10-02 17:00:16.123000000,1.334400,1.334600

In my code I have assumed prices are, as you would expect, numeric, text is a String and dates are Java Date (it's a little more complex but you get the idea). For dates the code allows you to pass a parsing template in. Up to now this has worked fine but I'm a little foxed as to what to do with these files (I have no control over the format and they are very large). As you will see the date has the form

2011-10-02 17:00:16.123000000

the six trailing zeros are always zero (i.e. the file time precision is down to milliseconds)

Ideally I would be able to use the pattern "yyyy-MM-dd HH:mm:ss.SSS" but sadly the parsing logic in SimpleDateFormat interprets ".123000000" as 123,000,000 milliseconds instead of 123ms.

Clearly if this were not a generic reader I could simply truncate the date string but I don't have that choice. Is there any way to get the parse statement to use the ms digits only and ignore the trailing zeros?

3
  • 1
    If you know the length of the passed-in date format, why can't you truncate the date value to that length?
    – GriffeyDog
    May 25, 2012 at 15:19
  • SimpleDateFormat is crude like that. SSS is for milliseconds, and milliseconds (as milli would imply) are three digits only. Perhaps, it's worth looking away from SimpleDateFormat to a different solution, otherwise - truncate.
    – maksimov
    May 25, 2012 at 15:22
  • Why does it appear like that?
    – adarshr
    May 25, 2012 at 15:23

1 Answer 1

3

Duplicate of Custom date format cannot be parsed. (Java)

The conclusion is: SimpleDateFormat does not support microseconds, hence a custom parser has to be written.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.