package com.tencent.javaBase;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class WeekCal {
	
	public static void main(String[] args) {
		getWeek("2017-12-25");
		getWeek("2017-12-26");
		getWeek("2017-12-27");
		getWeek("2017-12-28");
		getWeek("2017-12-29");
		getWeek("2017-12-30");
		getWeek("2018-12-31");
		getWeek("2018-01-01");
	}
	
	public static void getWeek(String date) {
		try {
	        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	        

	        Calendar cal = Calendar.getInstance();
	        cal.setFirstDayOfWeek(Calendar.MONDAY); // 设置每周的第一天为星期一
	        //cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);// 每周从周一开始
	        cal.setMinimalDaysInFirstWeek(1); // 设置每周最少为1天
	        cal.setTime(df.parse(date));
	        int week = cal.get(Calendar.WEEK_OF_YEAR);
	        System.out.println("date:"+date + " week:" + week);

	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}

}

@@ -87,16 +87,358 @@
 endar;%0A%0A
+/**%0A * %E8%AE%A1%E7%AE%97%E6%97%A5%E6%9C%9F%E5%B1%9E%E4%BA%8E%E4%B8%80%E5%B9%B4%E7%9A%84%E5%91%A8%E6%95%B0%0A * %0Aresult:%0Adate:2017-12-25 week:52%0Adate:2017-12-26 week:53%0Adate:2017-12-27 week:53%0Adate:2017-12-28 week:53%0Adate:2017-12-29 week:53%0Adate:2017-12-30 week:53%0Adate:2017-12-31 week:53%0Adate:2018-01-01 week:53%0Adate:2018-01-02 week:1%0Adate:2018-01-03 week:1%0Adate:2018-01-04 week:1%0Adate:2018-01-05 week:1%0A * @author ewanzhao%0A *%0A */%0A
 public c
@@ -495,16 +495,21 @@
  args) %7B
+%09%09%0A%09%09
 %0A%09%09getWe
@@ -665,17 +665,17 @@
 eek(%22201
-8
+7
 -12-31%22)
@@ -701,16 +701,116 @@
 1-01%22);%0A
+%09%09getWeek(%222018-01-02%22);%0A%09%09getWeek(%222018-01-03%22);%0A%09%09getWeek(%222018-01-04%22);%0A%09%09getWeek(%222018-01-05%22);%0A
 %09%7D%0A%09%0A%09pu
@@ -934,17 +934,16 @@
        %0A
-%0A
 %09       
@@ -1018,27 +1018,28 @@
 ek(Calendar.
-MON
+TUES
 DAY); // %E8%AE%BE%E7%BD%AE%E6%AF%8F
@@ -1052,77 +1052,8 @@
 %E6%98%9F%E6%9C%9F%E4%B8%80%0A
-%09        //cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);// %E6%AF%8F%E5%91%A8%E4%BB%8E%E5%91%A8%E4%B8%80%E5%BC%80%E5%A7%8B%0A
 %09   
@@ -1091,24 +1091,37 @@
 eek(
-1
+2
 ); // 
-%E8%AE%BE%E7%BD%AE%E6%AF%8F%E5%91%A8%E6%9C%80%E5%B0%91%E4%B8%BA1%E5%A4%A9
+%E6%96%B0%E7%9A%84%E4%B8%80%E5%B9%B4%E7%AC%AC%E4%B8%80%E5%91%A8%E8%87%B3%E5%B0%91%E6%9C%89N%E5%A4%A9%E5%9C%A8%E6%96%B0%E5%B9%B4%E9%87%8C%E6%89%8D%E5%B1%9E%E4%BA%8E%E7%AC%AC%E4%B8%80%E5%91%A8
 %0A%09  

test WeekCal api