Parse any date in Java

后端 未结 6 798
时光取名叫无心
时光取名叫无心 2020-11-22 07:31

I know this question is asked quite a bit, and obviously you can\'t parse any arbitrary date. However, I find that the python-dateutil library is able to parse every date I

6条回答
  •  故里飘歌
    2020-11-22 08:24

    You could try dateparser.

    It can recognize any String automatically, and parse it into Date, Calendar, LocalDateTime, OffsetDateTime correctly and quickly(1us~1.5us).

    It doesn't based on any natural language analyzer or SimpleDateFormat or regex.Pattern.

    With it, you don't have to prepare any appropriate patterns like yyyy-MM-dd'T'HH:mm:ss.SSSZ or yyyy-MM-dd'T'HH:mm:ss.SSSZZ:

    Date date = DateParserUtils.parseDate("2015-04-29T10:15:00.500+0000");
    Calendar calendar = DateParserUtils.parseCalendar("2015-04-29T10:15:00.500Z");
    LocalDateTime dateTime = DateParserUtils.parseDateTime("2015-04-29 10:15:00.500 +00:00");
    

    All works fine, please enjoy it.

提交回复
热议问题