Java Calendar Acts Differently on OSX Windows

Basically, I created a webapp meeting planner using Java servlets. It is heavily dependent on javas Calendar. All this was developed on my mountain lion macbook with jdk 1.6.

Now, when testing on my computer, I had some strange results.

Duration:

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 

Nevertheless, it will be displayed on the macro:

  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 the weekly schedule with these values, the mac will start at 6am on Sunday, which is contained in the current week. But the PC will start at 6am on Sunday, which will be presented next week.

This means that any assignments that I create are not synchronized on the PC (on different days before the expected) Note: the computer was tested with both jdk1.6 and jdk1.7

Does anyone know any solutions or reasons for this?

thanks

+6
source share
1 answer

Perhaps this is a language / time zone issue that may be different on both machines.
Make sure that both instances use the same language with hardcoding, for example:

 Calendar.getInstance(Locale.US); 

else getInstance () will use the standard locale of your system.

+4
source

All Articles