DateItem in smartGWT auto translate UTC date to local client browser date in Javascript

583 Views Asked by At

I am currently using smartGWT 4.1 in java to display UI element (dateItem) calendar to our clients

All the values(in java Date Object) are in UTC format. However, when passing into dateitem.setValue(date) Javascript from smartGWT auto translates the date value into local user browser timezone.

Since I need all the dates presented on the UI in the UTC format, is there any way to disable smartGWT (or javascript) auto translation?

I have tried pass the string value into the dateItem, but javascript will parse it back to date and the conversion will still happen. Also, I have tried DateUtil.setDefaultDisplayTimezone("00:00") but still nothing happens.

1

There are 1 best solutions below

0
On BEST ANSWER

did you try setting setShortDateDisplayFormatter:

DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
    public String format(Date date) {
        if(date == null) {
            return null;
        }
        DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd-MM-yyyy"+ "T"+"HH:mm:ss");
        return dateFormatter.format(date, TimeZone.createTimeZone(0));
    }
});