Edit: Thanks- I understand it a lot more now. Its very confusing when you first start! Thanks for the help. I am going to keep the question up as is ( in peril of more downvotes) as it might help others. There are some other libraries that everyone seems to recommend for date time
I am struggling with the Java calendar function- its seems to be returning wrong data the bottom figure should be a thursday according to calendar, but is returning as a saturday!
Calendar cal = new GregorianCalendar();
cal.set(2012,2,23); // 0 = January
String weekdays[]={"sunday","monday", "tuesday", "wednesday","thursday","friday","saturday",};
Integer Weekdaycurrent1=cal.get(Calendar.DAY_OF_WEEK);
System.out.println("today is a "+weekdays[Weekdaycurrent1]); //Prints today is Saturday, when it should be a thursday
For starters,
DAY_OF_WEEKis1based:Secondly,
2012-03-23(yes, Mar not Feb) as set bycal.set(2012, 2, 23)was a FridayYour code is behaving correctly.
Edited: For those too lame to read the question properly, calling
cal.set(2012,2,23)sets the date to2012-03-23, because themonthparameter is zero-based (ie Jan = 0, Feb = 1, Mar = 2, etc)