Basically i have built an appointment scheduler webapp using java servlets. It relies heavily on javas Calendar. The whole thing was developed on my macbook running mountain lion with jdk 1.6.
Now when testing it on my pc i have had some strange results.
Running:
System.out.println("selected = "+selected);
Calendar now = Calendar.getInstance();
System.out.println("a "+now.getTime());
now.setTimeInMillis(selected);
System.out.println("b "+now.getTime());
now.set(Calendar.MILLISECOND,0);
now.set(Calendar.SECOND,0);
now.set(Calendar.MINUTE,0);
now.set(Calendar.HOUR_OF_DAY,6);//start from 6am
System.out.println("d "+now.getTime());
now.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
System.out.println("e "+now.getTime());
on the PC will output:
selected = 1355835600000
a Wed Dec 19 19:35:36 EST 2012
b Wed Dec 19 00:00:00 EST 2012
d Wed Dec 19 06:00:00 EST 2012
e Sun Dec 23 06:00:00 EST 2012
Yet on the mac it will output:
selected = 1355835600000
a Wed Dec 19 19:33:57 EST 2012
b Wed Dec 19 00:00:00 EST 2012
d Wed Dec 19 06:00:00 EST 2012
e Sun Dec 16 06:00:00 EST 2012
As we can see here, if i build a table representing a weekly schedule off these values, the mac will start at 6am on the sunday contained in the current week. But the pc will start at 6am on the sunday contained in the next week.
Which means any appointments i create are out of sync on the pc (different days to whats expected) note: the pc has been tested with both jdk1.6 and jdk1.7
Does anyone know any solutions or reasons behind this?
Thanks
Possibly, this is a locale/timezone problem which might differ on both machines.
Make sure that both instances use the same locale by hard coding it for example:
Calendar.getInstance(Locale.US);
else getInstance() would use the default locale of your system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With