Showing posts with label utc. Show all posts
Showing posts with label utc. Show all posts

Tuesday, October 12, 2021

Grails saves datetime as UTC time, but reads it as local server time

Grails saves datetime as UTC time, but reads it as local server time???
The timestamp is read back as local time instead. So if my timezone is +2 UTC and the current local time is 12:30:00, what will be saved to the database is 10:30:00, but when I read it back, it becomes 10:30:00. Does anybody know how to fix this problem so that Grails will read the timestamp back as UTC and convert it accordingly?
I have the following line in my Grails application (BootStrap.groovy) to set the default timezone to UTC:
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
And above line solved my problem. Now I can set time anything to db and returned back the same date to my domain field