Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to show DateTime values in different timezone than browsers.

    My browser is in Eastern Timezone but I want to show the date times in a different timezone. I am using the DateUtil.setDefaultDisplayTimezone which does effect the time being selected so that it is in the timezone set by that method, however the display still shows the value in the browser's local timezone.

    For example, If i pick Jan 1st: 00:00 using the code below and setDefaultDisplayTimezone("-07:00") with my browser in Eastern Timezone, then the inputted date time is correct but it displays with timezone -5 and not -7.
    Likewise if I pick a date within DST such as Sept 1 00:00 then again it shows in browser relative Timezone of -4 instead of -6.

    How do i get the components to display in the Timezone that was set with setDefaultDisplayTimezone?

    Using: SmartClient Version: v10.1p_2015-12-18/Pro Deployment (built 2015-12-18)

    Code:
        public void onModuleLoad() {
            final DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss Z");
    
            DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter() {
                public String format(Date date) {
                    if (date == null) return null;
                    String formattedDate = dateTimeFormat.format(date);
                    return formattedDate;
                }
            });
    
            DateUtil.setDateParser(new DateParser() {
                public Date parse(String dateString) {
                    return dateTimeFormat.parse(dateString);
                }
            });
    
            DateUtil.setDefaultDisplayTimezone("-07:00");
            HLayout layout = new HLayout();
            DynamicForm form = new DynamicForm();
            RelativeDateItem date1 = new RelativeDateItem("date_1");
            RelativeDateItem date2 = new RelativeDateItem("date_2");
            date1.setTitle("Date_1");
            date2.setTitle("Date_2");
            form.setFields(date1, date2);
            layout.addMember(form);
            layout.draw();
        }
    Attached Files

    #2
    I know it is the formatter i am using since it has no knowledge of setDefaultDisplayTimezone. Just wondering if you have any suggestions?

    Comment


      #3
      The FormItems have no specified data-type - calling setType("datetime") on your RelativeDateItems should address this for you.

      Comment


        #4
        I found a solution by using the User TimeZone in the formatter so it displays the DateTime in the User TimeZone not the browsers.

        Comment


          #5
          After some more testing, we found that the actual valueField in RelativeDateItems was being formatted correctly, but that the calculated date field, to the right of the control, was not. The problem was that, in the absence of a data-type (logical "date" or "datetime"), some code was assuming logical "date"s, ie, ones with no time portion to be converted to the defaultDisplayTimezone. So this item was displaying the browser local time.

          We've fixed that in the current latest at smartclient.com/builds, so you can test it out if you like.

          Comment

          Working...
          X