Converter publicstatic Gson getGson(){ if (sGson == null) { sGson = new GsonBuilder()
.registerTypeAdapter(Event.EventDateTime.class, new DateDeserializer<Event.EventDateTime>( Event.EventDateTime.DATE_FORMAT, Event.EventDateTime.class))
.registerTypeAdapter(Event.StartEndDateTime.class, new DateDeserializer<Event.StartEndDateTime>( Event.StartEndDateTime.DATE_FORMAT, Event.StartEndDateTime.class))
.registerTypeAdapter(Event.SimpleDate.class, new DateDeserializer<Event.SimpleDate>( Event.SimpleDate.DATE_FORMAT, Event.SimpleDate.class)) .create(); }
What is the problem of the plain old Simple Date Format?
it is not thread-safe, i.e. an instance cannot be used concurrently by several Java threads. Its javadoc says: “It is recommended to create separate format instances for each thread.”
SimpleDateFormat can change its configured time zone if it is asked to parse a date with a different time zone [bug report]
creating new instances is not cheap. Its constructor compiles the passed date-time pattern and if you create a new instance of SimpleDateFormat for each usage then it usually appears in CPU profiling results.
try { val ta = DateTimeFormatter.ofPattern(fromPattern, Locale.US).parse(date) return DateTimeFormatter.ofPattern(toPattern, Locale.US).format(ta) } catch (e: Exception) {
}
LocalDate , LocalDateTime, LocalTime differences
Based on the naming, we can know that they are serve for different purpose, date only, time only or date and time together,
It is using system default timezone
However there are some drawbacks for them, let’s say if u are parsing LocalDateTime without time, it will throw DateTimeParseException, same for the other class.
Exception Sample
Reason why it happen: LocalTime was expecting 11:30 but not a full format, source code: