Dear all,
I have an application running on a server in the GMT timezone; I have users from all over the world. So, I want to display date/time information to users in their own timezone.
Mostly, I have grids with datetime columns and was displaying them as
grid.addColumn(new LocalDateTimeRenderer<>(MyObject::getDateUpdated, "yyyy-MM-dd HH:mm:ss"))
I searched and found that I can get offset from browser, then started to add offset to localdatetime in grid column. I get offset and store it in one of my user variables, then use it as below.
UI.getCurrent().getPage().retrieveExtendedClientDetails(details -> {
int offset = details.getTimezoneOffset();
userInformation.setOffset(offset/1000);
});
grid.addColumn(new LocalDateTimeRenderer<>((source) -> source.getDateCreated().plusSeconds(userInformation.getOffset()), "yyyy-MM-dd HH:mm:ss"))
Is this the preferred way? Is there any better way to convert timezone, e.g., ZonedDateTimeRenderer ??