SimpleDateFormat cannot parse milliseconds with more than 4 digits

前端 未结 7 727
花落未央
花落未央 2020-12-06 13:20

I want to parse a timestamp, like this - \"2016-03-16 01:14:21.6739\". But when I use the SimpleDateFormat to parse it, I find that it outputs an i

7条回答
  •  孤城傲影
    2020-12-06 13:53

    A little off-topic but SimpleDateFormat class is not thread safe - not only on parsing which is somewhat understandable but also on formatting. there are a lot of info on this on the net, here is one example: http://javarevisited.blogspot.co.il/2012/03/simpledateformat-in-java-is-not-thread.html. This problem will not be fixed. In Java 8 there is a whole new package java.time with wonderful new features allowing to work with full or partial dates and times. Also there is a new class DateTimeFormatter that provides vastly improved formatting and parsing features. However, if you use java older then java 8 then the recommendation would be to use Joda time library or Apache FastDateFormat

提交回复
热议问题