I have a datetime column in mysql database (colum is called creation_date), everytime im going to save the entity that has that column I fill that column like so (it is a LocalDateTime in my java class):
public static LocalDateTime argDate() {
return LocalDateTime.now(ZoneId.of("America/Argentina/Buenos_Aires"));
}
So I need to make a calculation with that date, to check which records have certain conditions and one of those is if the time between the current date and that "creation_date" is equal or higher than 70 seconds, do something with that, so I would like to make sure I am working with only Argentina time to have accurate results and no mistakes, so this works:
long seconds = ChronoUnit.SECONDS.between(entity.getCreationDate(), argDate());
that method works, but I wanted to be 100% sure that I am working with Argentina date, so I tried this but started getting the error in the title:
long seconds = ChronoUnit.SECONDS.between(entity.getCreationDate().atZone(ZoneId.of("America/Argentina/Buenos_Aires")), argDate());
The thing is I have many questions right now, one is if the column type at Mysql will always give me back the datetime in Argentina time because since I am always saving it with that ZoneId, I would expect that to be that way...
And another one is how can I fix that error on the title? So I make sure I am working with Argentina time and the calculation of the seconds is good
So far I believe that my assumption that the Mysql datetime being in Argentina time is correct, because I decided to log some entries and this is the output:
LocalDateTime now = argDate();
log.info("database entity creation_date (arg): {}, now (arg): {}", entity.getCreationDate(), now);
Output:
database entity creation_date (arg): 2023-07-20T15:08:25, now (arg): 2023-07-20T15:09:24.013604344
But my fear is that maybe this is not true? And the timezone of the server of the database is argentina time luckyly? Or is it respecting the zoneId I gave it when saving it
Research:
According to this answer I should not worry about this scenario, since it is a datetime column it will respect the zoneId I gave it before saving it (Argentina), so when I retrieve this from database it will already be in Arg time, but still curious of how to fix the error on title