获得当前周别所属年份

来源:互联网 发布:收集5条红酒网络广告语 编辑:程序博客网 时间:2024/06/05 03:05




获得当前周别所属年份

  1. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");   
  2. Calendar cl = Calendar.getInstance();   
  3. cl.setTime(sdf.parse("2012-12-31"));   
  4. int week = cl.get(Calendar.WEEK_OF_YEAR);   
  5. System.out.println(week);   
  6. cl.add(Calendar.DAY_OF_MONTH, -7);  
  7. int year = cl.get(Calendar.YEAR);  
  8. if(week<cl.get(Calendar.WEEK_OF_YEAR)){  
  9.     year+=1;  
  10. }  
原创粉丝点击