SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD'T'HH:mm:ssZ");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
String _fromTime = sdf.format(_fromDate);
String _toTime = sdf.format(_toDate);
ADD_JSON_OBJECT.put("publish_up", new JsonObject()
.put("$date", _fromTime));
ADD_JSON_OBJECT.put("publish_down", new JsonObject()
.put("$date", _toTime));
java.time.format.DateTimeParseException: Text '2015-01-08T06:00:00+0000' could not be parsed at index 19
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
at java.time.OffsetDateTime.parse(OffsetDateTime.java:402)
java.time.format.DateTimeParseException: Text '2015-01-08T13:00:00' could not be parsed at index 19
I think the problem is with
ADD_JSON_OBJECT.put("publish_up", new JsonObject()
.put("$date", _fromTime));
mongo.insert(DEAL_COLLECTION, ADD_JSON_OBJECT, res -> {
if (res.succeeded()) {
updateCounter();
} else {
res.cause().printStackTrace();
}
});
public static String getISO8601StringForDate(Date date) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(date);
}