-
FEATURED COMPONENTS
First time here? Check out the FAQ!
We are having a problem with our dateboxes. If the user chooses the 01-01-1970 on a datebox, after the component looses focus the date being shown is 31-12-1969.
We have a prefered timezone and then some of our pages have a specific timezone. The user should input the date according with the page's timezone and the date is converted to milliseconds with the timezone UTC. These are the configurations we have for the timezones used in the components:
Our expectations were that the timezone defined at the ZUL (Europe/Lisbon) overrides the other definitions, however the result is not consistent.
We created the next class to show us the expected time in milliseconds for the dates.
package dateCalculation;
import java.util.Calendar;
import java.util.TimeZone;
public class EuropeLisbonDateGenerator {
public static void main(String[] args) {
printLisbonDatesSince1970();
}
private static void printLisbonDatesSince1970() {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Europe/Lisbon"));
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
for(int year = 1970; year < 2017; year++) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
System.out.println("1 January " + year + ": " + calendar.getTimeInMillis());
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, Calendar.JULY);
System.out.println("1 July " + year + ": " + calendar.getTimeInMillis());
}
}
}
This were the results:
Inputed value: 01-01-1970 (dd-mm-yyyy). The actual date in millis inside the custom converter: 0 (not ok). The expected date in millis inside the custom converter: -3600000
Inputed value: 01-07-1970 (dd-mm-yyyy). The actual date in millis inside the custom converter: 15638400000 (ok). The expected date in millis inside the custom converter: 15638400000
Inputed value: 01-01-2016 (dd-mm-yyyy). The actual date in millis inside the custom converter: 1451606400000 (ok). The expected date in millis inside the custom converter: 1451606400000
Inputed value: 01-07-2016 (dd-mm-yyyy). The actual date in millis inside the custom converter: 1467327600000 (ok). The expected date in millis inside the custom converter: 1467327600000
Do you know how to fix this problem?
Hello eclipse1,
Solution may be quite simple. Just add a constraint for the date value to be after 01-01-1970.
Check section constraints:
https://www.zkoss.org/wiki/ZKComponentReference/Input/Datebox
Best Regards,
Darksu
Asked: 2016-10-24 10:06:02 +0800
Seen: 44 times
Last updated: Oct 30 '16