0

I have following issue. On client side ( GWT ) I have function

String getFormattedDateFromServer(Date dateFromServer) 

which should get date from server in UTC time and return formatted date in client local time

It was implemented as following:

public static String getFormattedDateFromServer(Date dateFromServer) {
        int offset = new Date().getTimezoneOffset();
        TimeZone localTimeZone = TimeZone.createTimeZone(offset);
        return DateTimeFormat.getFormat("MM/dd/yyyy hh:mm").format(dateFromServer, localTimeZone);
    }

When running on client in GMT+2 timezone on date 04/05/2020 00:00 it was expected 04/05/2020 02:00. But I am getting 04/05/2020 00:00. As I understand this is because on client side date 04/05/2020 00:00 considered already in local time (i.e. GMT+2) .For server side as I see in other posts it can be see via SimpleDateFormat class and manualy set timezon ( like here )

But SimpleDateFormat cannot be used for GWT. The question is how can it be done for GWT ? Or there are better solutions ? Thanks in advance

lm.
  • 4,033
  • 4
  • 25
  • 37
  • Related: [GWT: use DateTimeFormat on client and SimpleDateFormat on server](https://stackoverflow.com/questions/10284564/gwt-use-datetimeformat-on-client-and-simpledateformat-on-server). Search for more. – Ole V.V. Jan 08 '23 at 13:39

0 Answers0