I want to return the week and year of a date like 2016/06
. Therefore I use the following code to try it out:
public static void main(String[] args) throws ParseException {
DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
DateFormat formatWeekAndYear = new SimpleDateFormat("yyyy/ww");
String articleDate = "31.12.2015 11:26:00";
long keyDate = format.parse(articleDate).getTime();
System.out.println("KeyDate: " + keyDate + " = " + format.format(keyDate));
String formatted = formatWeekAndYear.format(keyDate);
System.out.println(formatted);
}
I want to return a <Year> / <Week Of Year>
string for any input date, e.g. 31.12.2015 11:26:00
(see code).
Now the strange behavior:
I get different results, dependent on which computer I run the Java program!
Here the output on my local PC:
KeyDate: 1451557560000 = 31.12.2015 11:26:00
2015/53
Running exact the same program on a remote machine I get:
KeyDate: 1451557560000 = 31.12.2015 11:26:00
2015/01
Why returns computer A 2015/53
and the other 2015/01
. It took me days to find out this difference, can someone give an explanation?