Alternatives to FastDateFormat for efficient date parsing?

后端 未结 6 924
-上瘾入骨i
-上瘾入骨i 2021-02-05 04:29

Well aware of performance and thread issues with SimpleDateFormat, I decided to go with FastDateFormat, until I realized that FastDateFormat

6条回答
  •  攒了一身酷
    2021-02-05 05:25

    At a best guess, it's to keep FastDateFormat... well... fast, by limiting it to display only.

    Apache Commons DateUtils has a parseDate function, but that uses SimpleDateFormat internally.

    An alternative is to use the JodaTime library. It's a complete replacement for dealing with DateFormat, Date, and Calendar objects.

    JodaTime has a DateTimeFormatter that can be used to create DateTime objects (JodaTime's equivalent of Java's Date objects) from strings.

    An example of how to use it is like this:

    String strInputDateTime = "2010-12-27"; // An example, this would really come from outside
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTime dt = fmt.parseDateTime(strInputDateTime);
    

    I don't know if this is really any faster than SimpleDateFormat, though.

提交回复
热议问题