I tried getting week of the year through below code but it always returns "3", I even set the timezone to GMT but still returning the same value("3"
). Please help me out over here
DateFormat formatter = new SimpleDateFormat("dd-mm-yyyy");
Date date = formatter.parse("14-10-2014")
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println(calendar.get(Calendar.WEEK_OF_YEAR));
You're setting the minutes not the month. It sounds like it's parsing this as 2014-01-14T00:10:00, and that January 14th 2014 is in the third week. You want MM
for months, not mm
.
(I'd also encourage you to use yyyy-MM-dd
if you get a chance to change the format entirely - that's ISO-8601 compliant...)
See more on this question at Stackoverflow