Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

398
Vistas
Spring Data MongoDB - when saving LocaDate/LocalDateTime the value is being set to yesterday

I've got a problem with saving Java8 Date API values to MongoDB database. Whenever a new LocalDate instance (LocalDate.now()) is being saved, as a result we are getting value with yesterdays date with time set to 23:00 PM. Example:

dt.getDate().toString() 

is giving me "2017-03-17"

but when i look into the database i have a value like this:

"dt" : ISODate("2017-03-16T23:00:00.000Z")

My time zone is UTC+01:00

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

MongoDB saves the date in UTC time.

LocalTime is your wall clock time.

When you pass it to MongoDb, spring will convert the LocalTime to Instant(UTC time) by using your System Zone.

Consider

LocalDateTime localDateTime = LocalDateTime.parse("2017-03-17T00:00:00")

Something like this happpens

Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();

This is where your local time is changed to UTC instant by applying offset (+01:00) from your local time.

Output(in UTC) : 2017-03-16T23:00:00.000Z 
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda