0

ZK9 java.util.Date has timezone applied

asked 2020-01-23 10:31:48 +0800

JustinFrost gravatar image JustinFrost
145 1 6

updated 2020-01-23 10:33:33 +0800

Hi we are passing java.util.Date to our custom ZK components using binding, eg:

<dateroller startDate="@bind(model.startDate)"/>

There seems to be an issue with the date applying the jvm default timezone somewhere. The java.util.Date has the time set to 9:00

When we inspect this in the javascript widget it comes through as a instance of DateImpl as UTC, but when we get the date using val._moment.toDate() it returns a date with the local timezone applied which means the time is changed from the original value of 9:00.

This only seems to happen if the JVM has a different timezone to the browser.

Since java.util.Date has no timezone, how do we get the unchanged value on the javascript side ?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-01-31 18:22:00 +0800

MDuchemin gravatar image MDuchemin
1561 1 5
ZK Team

Hi There,

You will already get some info from the timezone doc page here.

A simple way to get every date object in the same timezone is to set a timezone for the whole app, in zk.xml or in Java

<library-property>
    <name>org.zkoss.web.preferred.timeZone</name>
    <value>GMT-8</value>
</library-property>

or 1

Library.setProperty(Attributes.PREFERRED_TIME_ZONE, "PST");

This will force all dates to be interpreted in the same timezone even on clients holding a different timezone from the server.

link publish delete flag offensive edit

Comments

Thanks for the reply. I have tried using both of those options, but they have no effect the only thing that changes the date on the client side is if I set the java user.timezone parameter:

-Duser.timezone=PST for example. What does it assume the timezone of the java.util.Date to convert is ?

JustinFrost ( 2020-02-02 10:15:18 +0800 )edit
0

answered 2020-02-04 07:18:29 +0800

JustinFrost gravatar image JustinFrost
145 1 6

@MDuchemin

If I change the system property -Duser.timezone=UTC then when I execute :

smartUpdate("toDate", value);

with a java,util.date of 2020-01-24 09:00

Then the DateImpl object on the client side has the associate moment object UTC date set correctly to the above. When I execute the following to get the javascript date:

setFromDate: function(val){
        if (val instanceof DateImpl)
            val = val._moment.toDate();

Because I am creating a javascript date it uses the local timezone applied to the UTC. I have worked around this by hacking the javascript date to be equivalent to the UTC date (which has the time correct).

Do you know why none of the ZK PREFERREDTIMEZONE methods described in the documentation are working for me ? It seems to be using the java default timezone all of the time.

Thanks.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-01-23 10:31:48 +0800

Seen: 14 times

Last updated: Feb 04

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More