Java SimpleDateFormat.Parse

I wrote a generic CSV file, which I am trying to use to read some files of generated CSV files. These files contain pricing 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 assumed that prices are, as you would expect, numeric, text is String, and dates are Java dates (this is a bit more complicated, but you get the idea). For dates, the code allows you to go through a parsing pattern. So far, this has worked fine, but I'm a bit lacking in information on what to do with these files (I have no control over the format, and they are very large). Since you will see that the date has the form

2011-10-02 17:00:16.123000000

six trailing zeros are always zero (i.e. file time accuracy less than milliseconds)

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

Clearly, if it weren't for the general reader, I could just truncate the date string, but I don't have that choice. Is there a way to force the syntax operator to use only ms digits and ignore trailing zeros?

+3
source share
1 answer

Duplicate Custom date format cannot be parsed. (Java)

Conclusion: SimpleDateFormatdoes not support microseconds, so a custom parser should be written.

+3
source

All Articles