我试图从一个季度内的日期获得周数。
从下面我可以得到一年中的周数,但不是在季度内。
String input = "20130805";
String format = "yyyyMMdd";
SimpleDateFormat df = new SimpleDateFormat(format);
Date date = df.parse(input);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int week = cal.get(Calendar.WEEK_OF_YEAR);
结果应该是第3季的周数
答案 0 :(得分:0)
做一个模数会给你答案:
int x = 52 / 4; //52 week as ave in a year
System.out.println(week);
System.out.println("you are in the quartal number: " + (week / x + 1));
System.out.println("this is the week number: " + week % x + " in the quartal");
答案 1 :(得分:0)
试试这个,
String input = "20130805";
String format = "yyyyMMdd";
SimpleDateFormat df = new SimpleDateFormat(format);
Date date = df.parse(input);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int weekForYear = cal.get(Calendar.WEEK_OF_YEAR);
int previousQuarter = (date.getMonth() / 3);
System.out.println("No. of weeks for current Quarter: " + weekForYear - (previousQuarter*13));