I want to get the format of a given date string.
Example: I have a string like 2011-09-27T07:04:21.97-05:00
and the date format of this string is
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'Z'
or MM/dd/yyyy HH:mm:ss
etc:
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");
And it has better performance than loop-try multiple SimpleDateFormat
.
Please enjoy it.