First time here? Check out the FAQ!
Hi all,
In our application we have a date that is: 29-jun-2021 0:00:00
When we use the default zk date formatter: @converter('formatedDate', format='dd-MM-yyyy') it displays the following:
28-06-2021
Does anyone know why the date changes? We are using zk version 8.6.0.1 at the moment.
Kind regards,
Remie
Thanks for the info MDuchemin. That is really helpfull. I have now discovered that if i use Sessions.getCurrent(); and set the timezone to Amsterdam, the value gets overriden upon entering a regular VM.
In my Debug console i can see that the value of the session attribute is:
org.zkoss.web.preferred.timeZone -> {[email protected]} "sun.util.calendar.ZoneInfo[id="GMT+01:00",offset=3600000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]"
It seems that the application itself is using the sun package to interfere. I have to investigate is further.
I see. If i create my own converter it does exactly do what i expected: 2021-06-28. The Date is a CET type and will convert fine.
However looking at https://www.zkoss.org/wiki/ZKDeveloper'sReference/Internationalization/Time_Zone
I change my example after login to:
TimeZone preferredTimeZone = TimeZone.getTimeZone("Europe/Amsterdam");
Executions.getCurrent().getDesktop().setAttribute(Attributes.PREFERREDTIMEZONE, preferredTimeZone);
My datebox: <datebox value="@load(line.field('BestBeforeDate').value)" format="YYYY-MM-dd HH:mm:ss Z"/> still shows: 1-06-28 23:00:00 1.
I expected it to be: 1-06-28 00:00:00
Also, depending on how you set the timezone, the setting may not apply before the next page load. A reliable way to set is at server start, with the library property: <library-property> <name>org.zkoss.web.preferred.timeZone</name> <value>time zone here</value> </library-property>
MDuchemin ( 2020-10-30 18:41:11 +0800 )editYou can make your own converter and pass it from the VM instead of using the default.
http://books.zkoss.org/zk-mvvm-book/8.0/syntax/converter.html
Just implement a class with the converter interface, instantiate one in the VM (with a getter) and pass it to the compoenent:
<datebox value="@load(vm.myDate) @converter(vm.customDateConverter)"/>
If you are using the default converter, you can check ZK's date handling here regarding timezones: https://www.zkoss.org/wiki/ZKDeveloper'sReference/Internationalization/Time_Zone
most likely a time zone (and or DST) issue.
e.g.: if your date at server side is using UTC and is then displayed using "New York" 2021-06-29 0:00 GMT+0 will become 2021-06-28 8:00pm GMT-4
In order to debug simply append the HH:mm:ss Z
to the date time format just to see the time and timezone information helping you to debug this in more detail.
<datebox width="300px" format="YYYY-MM-dd HH:mm:ss Z" />
Asked: 2020-10-29 23:14:04 +0800
Seen: 14 times
Last updated: Oct 30 '20
Starting An OnLine Store? [closed]
Date box format and bind time field value
Date is changed on the datebox after the user's input
How to set Tooltip Format in zk ?
Validate datebox invalid input with validators
How to apply style for Slider needle in slider component