Hi, I had to write a small java method to convert a date into a progressive day of the year.
I used the GregorianCalendar in this way:
cal.clear();
cal.set(year,month,day); //where year,month,day are 2006, 1,1 for testing purpose
cal.get(Calendar.DAY_OF_YEAR);
and the result is 32, WTF? But if I use cal.get(Calendar.YEAR); cal.get(Calendar.MONTH); cal.get(Calendar.DATE); I get correct values.
I also tried with 2006 11 16 and I get 350, wich seems to be wrong.
Am I missing something?
BTW, I solved the issue using
cal.clear();
cal.setTime(new SimpleDateFormat("yyyyMMdd").parse("20061116"));
cal.get(Calendar.DAY_OF_YEAR);
surrounded by a try block to catch a FormatException, that is, passing to cal a Date Object created using an input string.
Why is the other way wrong? Just curiosity...
Thanks guys!