javatimezonejvx

Timezone support in JVx


I have a requirement for a new application. The application should show date/time values for different timezones. The stored date is always the same, but different clients in different timezones should see the local date/time.

But not all date/time values should be localized. Some date values should be fixed to a specific timezone because of admin screens and filtering.

How could I solve this with JVx?

I tried to search the documentation but didn't find anything helpful. Only that there's a parameter for setting the timezone. But there's no description.


Solution

  • There are different time zone settings used in jvx.

    The server uses the java default logic with TimeZone.getDefault(). If the application server is started with GMT/UTC, all the date/time will be stored with this time zone in the database. The server time zone can be set on application server startup (eg. java -Duser.timezone=UTC). By default it will be the system time zone of the server.

    The default client time zone is the time zone of the client device used by jvx (time zone of browser or mobile device). As stated in previous answer, it can be overruled in application.xml or programmatically in own application with setTimeZoneId(String pTimeZoneId). If the server time zone is set/configured on client, all clients will show the same date/time as stored in database.

    It is also possible, to show one date/time in different editors in different time zones. The following example will show the column DATE_COLUMN in either UTC and CET. Both can be edited and will always show the correct date/time in the configured time zone.

    // Set UTC time zone
    UIDateCellEditor dceTimeZoneUTC = new UIDateCellEditor(DateUtil.getDefaultDateTimeShortPattern());
    dceTimeZoneUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
    
    // Set CET time zone
    UIDateCellEditor dceTimeZoneCET = new UIDateCellEditor(DateUtil.getDefaultDateTimeShortPattern());
    dceTimeZoneUTC.setTimeZone(TimeZone.getTimeZone("CET"));
    
    // Create UIEditor object with UTC time zone
    UIEditor editorUTC = new UIEditor();
    editorUTC.setDataRow(mdbDateTest);
    editorUTC.setColumnName("DATE_COLUMN_NAME");
    editorUTC.setCellEditor(dceTimeZoneUTC);
    
    // Create UIEditor object with CET time zone
    UIEditor editorCET = new UIEditor();
    editorCET.setDataRow(mdbDateTest);
    editorCET.setColumnName("DATE_COLUMN_NAME");
    editorCET.setCellEditor(dceTimeZoneCET);