0

They have used GWT to create a form which contains date pickers when user submits the form, dates selected shifts one day back. e.g. if i select 21/06/2015 it shifts to 20/06/2015. This is happening when users time zone is different from server time zone. When i debug it, i found that it shifts one day back while converting date to calendar because Date is client zone's Date and Date to Calendar conversion is happening in server side for sending it to marshalling(before sending request to rest service API for saving).

Following code is used for converting date to calendar.

    Calendar cal = Calendar.getInstance();
    int offset = date.getTimezoneOffset();
    logger.info("Calendar Instance - " + cal);
    cal.setTime(date);
    logger.info("Calendar Instance after setting date - " + cal);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    logger.info("Calendar Instance after setting zeros - " + cal);
    return cal;

In last log it displays one day less than actual date. it works fine if i remove the following code.

    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

for IST and PST but not to other timezones. Please help.

bharath kumar
  • 21
  • 1
  • 1
  • 4

0 Answers0