Question Details

No question body available.

Tags

java spring mongodb spring-boot jparepository

Answers (6)

January 11, 2026 Score: 2 Rep: 1 Quality: Low Completeness: 10%

Use Instatnt for createdDate and modifiedDate in a Spring Boot (Java 17) application with MongoDB. MongoDB stores dates in UTC, and Instant represents a precise moment on the UTC timeline, making it timezone-safe and consistent across microservices. LocaleDateTime does not contain timezone information and can lead to inconsistencies when applications run in different environments. Since these fields are only for auditing,Instant is the best and recommended practice.

January 11, 2026 Score: 0 Rep: 87,512 Quality: Low Completeness: 30%

Correct. You can’t use LocalDateTime for a point in time since it does not define one.

January 11, 2026 Score: 0 Rep: 154 Quality: Low Completeness: 20%

Use Instant or ZonedDateTime. Do not use LocalDateTime.

ZonedDateTime adds additional abilities about conversion between geographical zones. Therefore ZonedDateTime is a better choice only if you have to handle zone conversions within your backend. If not then Instant is my default choice as it is the simplest one. Instant handles the reading of the dates with times from your mongodb and their exposure in the standard ISO 8601 format in the controller endpoint without any additional effort.

LocalDateTime means date and time in the locale of your backend application which is generally not UTC. Using LocalDateTime would require to handle painful additional conversions to account for the time zone of the backend application.

January 11, 2026 Score: 0 Rep: 60,460 Quality: Low Completeness: 70%

According to new features of the 3.7 Java driver: "Instant, LocalDate & LocalDateTime support" it should not matter what your are using. In MongoDB date values are stored as BSON Date type and always UTC time. So, I assume (I am not familiar with Java) no matter which Java Data type you are using, the driver will convert it properly to BSON Date value which is then stored in MongoDB. As general rule, you should never store date/time values as string, it's a design flaw and applies to any kind of database.

January 11, 2026 Score: 0 Rep: 260 Quality: Low Completeness: 20%
January 11, 2026 Score: 0 Rep: 41,421 Quality: Low Completeness: 10%

If dates will be used across different time zones (or there's such possibility), you always should go for UTC dates.

If this data is generated and used only in single time zone, then you can use local date time.