0

I have a 'simple' problem with Java and dates. I thought it was simple but I don't understand how to solve it ! I have try a lot of things. Here is the problem.

I save a date in my postgres sql database like this.

user.setCreationDate(Timestamp.valueOf((LocalDateTime.now())));

this date is store with one hour less than the real hour here. When I want to use it, I would like to get in database and add the UTC +1 of my local zone.

I try this but always get the date -1h...

OffsetDateTime myNewDate = bddDate.toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime()

Do you have an idea of how just get the local timezone exact hour ?

Thanks for your help !

Jeff
  • 59
  • 2
  • 10
  • 2
    Presumably related to either timezone or daylight savings. I'd use `Timestamp.from(Instant.now())`, might make a difference. – Michael Jan 21 '21 at 13:18
  • 1
    Does it answer your question? [Converting date to timestamp with timezone in Java](https://stackoverflow.com/questions/65352082/converting-date-to-timestamp-with-timezone-in-java) – Arvind Kumar Avinash Jan 21 '21 at 13:20
  • 1
    Does it answer your question? [Datetime behind an hour after insertion. Daylight savings](https://stackoverflow.com/questions/65812572/datetime-behind-an-hour-after-insertion-daylight-savings/65813340) – Arvind Kumar Avinash Jan 21 '21 at 13:22

0 Answers0