JAVA Calendar 正确获取年份与周数

from http://www.iteye.com/problems/91538

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");   
Calendar cl = Calendar.getInstance();   
cl.setTime(sdf.parse("2012-12-31"));   
int week = cl.get(Calendar.WEEK_OF_YEAR);   
System.out.println(week);   
cl.add(Calendar.DAY_OF_MONTH, -7);  
int year = cl.get(Calendar.YEAR);  
if(week.get(Calendar.WEEK_OF_YEAR)){  
    year+=1;  
}  
System.out.println(year+"年第"+week+"周");   

你可能感兴趣的:(java)