Storing java 8 LocalDate in mongo DB

前端 未结 2 968
[愿得一人]
[愿得一人] 2021-01-04 08:53

Using Spring boot 1.5.4.RELEASE and Mongo driver 3.4.2.

I want to store LocalDate in mongo DB, but I am facing a

2条回答
  •  萌比男神i
    2021-01-04 09:13

    The mongo-java client for a date object returns as instance of java.util.Date.

    The problem could possibly be that while you save the startDate and the endDate value, its toString() method would probably use the JVM's default time zone to update the value.

    The doc here states that The official BSON specification refers to the BSON Date type as the UTC datetime. and that could be the reason your LocalDateTime attributes were converted to the UTC time zone prior to being saved to the DB.

    Also to avoid such confusion would suggest using the bson type timestamp to update date fields.

提交回复
热议问题