datetime - Custom date format cannot be parsed. (Java) -


I have to use a custom date format in Java, because it has microseconds, though Java does not provide support for microseconds due to it I filled the time pattern with zero, which works fine during formatting, but I can not parse the date string with that pattern.

Is there any simple solution or self-microswond string functions?)

  @Test Public Zero TestDataformats () ParseException throws {DateFormat format = New SimpleDateFormat ("yyyy-MM-dd-HH.mm.ss.SSS000"); String theDate = format.format (new date ()); // it will fail: format.parse (theDate); }  

java.text.ParseException: ineffective date: "2010-01-25-12.40.35.769000"

Your problem is that the patterns used in SimpleDateFormat differ from unfortunately, its basis is whether it is used as a parser or as a formater or not. As a formatter, your pattern is expected, the output will end up with three-digit formatted millisecond value as three digits, such as:

2010-01-25-14.17. 47.307000

is used as a parser, the "SSS" pattern, however, corresponds to an arbitrary number of digits and parses as 307000 MS as the example given above. After parse MS Field, the parser will still search for a "000" object and will fail with an exception, because you have reached the end of the input string without meeting the requirements of the pattern.

There is no pattern for the value of any μs in the simple data format, so you have to type it before you can easily format the input string for the last three letters in order to write your simple wrapper.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -