MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

date in MongoDB:quando si inseriscono oggetti Date nel database Mongo, la data diventa 1 giorno prima di se stessa

final String dateString = "Jan 2, 2012";
final DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendMonthOfYearShortText().appendLiteral(" ").appendDayOfMonth(1).appendLiteral(", ").appendYear(4, 4).toFormatter();
final DateTime jodaDate = dtf.parseDateTime(dateString);
System.out.println(jodaDate);
final Date javaDate = new Date(jodaDate.getMillis());
System.out.println(javaDate); 

L'output è

2012-01-02T00:00:00.000+02:00
Mon Jan 02 00:00:00 EET 2012  

Avanti per:

final String dateString = "Jan 1, 2012";

l'output è:

2012-01-01T00:00:00.000+02:00
Sun Jan 01 00:00:00 EET 2012