We have code very much like the code below where we take a java.util.Date and minus a certain amount of seconds from the date and store it as a string in a sqlite db:
private static final String DB_DATE_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ssZ"
SimpleDateFormat DATE_FORMAT_NO_MS = new SimpleDateFormat(DB_DATE_FORMAT_STRING, Locale.US);
String dateToString(java.util.Date date date) {
return DATE_FORMAT_NO_MS.format(date);
}
then later we use the same string in a java 8 DateTimeFormatter to make a Java 8 OffsetDateTime:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DB_DATE_FORMAT_STRING);
OffsetDateTime odt = eventData.setDateReceived(OffsetDateTime.parse(dateString, eventDbTimeFormatter));
We keep getting crash reports like the one below when parsing the db string back into a OffsetDateTime:
2019-0005-12T12:07:47-0500' could not be parsed at index 7 org.threeten.bp.format.DateTimeFormatter.parseToBuilder
How can the month become 0005 for a SimpleDateFormat?