2012 年 1 月 2 日Instant.parse () メソッドの後、インスタント インスタンスは 1 日早い 2012 年 1 月 1 日の日付になります。元の日付文字列が 2012 年 1 月 1 日である場合、インスタントは 2011 年 12 月 31 日の日付になります。
String dateString="Jan 1, 2012";
Instant instant = Instant.parse(dateString, new DateTimeFormatterBuilder()
.appendMonthOfYearShortText()
.appendLiteral(" ")
.appendDayOfMonth(1)
.appendLiteral(", ")
.appendYear(4, 4)
.toFormatter());
DateTime dateTime = new DateTime(instant);
Date date = new Date(dateTime.getMillis());
document.append("time", new Date(dateTime.getMillis()));
tagsDbCollection.insert(document);
これらの日付を保存するために MongoDB を使用しています。私はテストしましたが、日付文字列をフォーマットすると表示されます->インスタントには間違いはありません。しかし、この Date 型のオブジェクトを MongoDB に挿入すると、MongoDB の日付文字列が 1 日早くなります。
MongoDB では:
/* 0 */
{
"_id" : ObjectId("50221a40da74d74053abb445"),
"time" : ISODate("2011-12-31T14:00:00Z")
}