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

public class DateFormatDemo {
    public static void main(String[] args) {
        formatDemo();
        dateCalc();

        Date begin = new Date(2017, 10, 5, 6, 0);
        Date end = new Date(2018, 10, 5, 6, 0);
        System.out.println(calcDateDiffSeconds(begin, end));
        System.out.println(calcDateDiffSeconds(begin, end));
    }

    public static int calcDateDiffSeconds(Date begin, Date end) {
        Long value = (end.getTime() - begin.getTime()) / 1000;
        return value.intValue();
    }

    public static void formatDemo() {
        // see http://developer.android.com/reference/java/text/SimpleDateFormat.html
        String format = new String("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
        System.out.println(sdf.format(new Date()));

        Calendar cal = Calendar.getInstance();
        System.out.println(sdf.format(cal.getTime()));

        // Month and day string
        System.out.println(getMonthAndDay(cal));
    }

    public static String getMonthAndDay(Calendar cal) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd", Locale.US);
        String monthAndDay = sdf.format(cal.getTime());
        return monthAndDay;
    }

    public static void dateCalc() {
        // 
        Calendar base = Calendar.getInstance();
        // 趨Ϊĳ
        base.set(2015, 3 - 1, 1);  // ·ݴ0ʼ3Ҫд2

        // 
        Calendar monday = DateCalcUtil.calc(base, DateCalcUtil.GET_THIS_MONDAY);
        Calendar sunday = DateCalcUtil.calc(base, DateCalcUtil.GET_THIS_SUNDAY);

        // 
        Calendar nextMonday = DateCalcUtil.calc(base, DateCalcUtil.GET_NEXT_MONDAY);
        Calendar nextSunday = DateCalcUtil.calc(base, DateCalcUtil.GET_NEXT_SUNDAY);

        // 
        Calendar previousMonday = DateCalcUtil.calc(base, DateCalcUtil.GET_PREVIOUS_MONDAY);
        Calendar previousSunday = DateCalcUtil.calc(base, DateCalcUtil.GET_PREVIOUS_SUNDAY);
    }

    static class DateCalcUtil {
        public static final int GET_PREVIOUS_MONDAY = 0;
        public static final int GET_PREVIOUS_SUNDAY = 1;
        public static final int GET_THIS_MONDAY = 2;
        public static final int GET_THIS_SUNDAY = 3;
        public static final int GET_NEXT_MONDAY = 4;
        public static final int GET_NEXT_SUNDAY = 5;

        public static Calendar calc(Calendar base, int calcType) {

            int min = base.getActualMinimum(Calendar.DAY_OF_WEEK); // ȡһܿʼ׼
            int current = base.get(Calendar.DAY_OF_WEEK); // ȡһ
            Calendar calendar = (Calendar)base.clone();

            int nCount = (current == min) ? -6 : (min - current + 1);

            switch (calcType) {
                case GET_PREVIOUS_MONDAY:
                    nCount -= 7;
                    break;

                case GET_PREVIOUS_SUNDAY:
                    nCount -= 1;
                    break;

                case GET_THIS_MONDAY:
                    break;

                case GET_THIS_SUNDAY:
                    nCount += 6;
                    break;

                case GET_NEXT_MONDAY:
                    nCount += 7;
                    break;

                case GET_NEXT_SUNDAY:
                    nCount += 13;
                    break;

                default:
                    break;
            }

            calendar.add(Calendar.DAY_OF_WEEK, nCount);
            
            return calendar;
        }
    }
}

@@ -1376,32 +1376,34 @@
 () %7B%0A        // 
+%E4%BB%8A%E5%A4%A9
 %0A        Calenda
@@ -1450,11 +1450,15 @@
  // 
-%E8%B6%A8%CE%AA%C4%B3
+%E5%8F%AF%E4%BB%A5%E8%AE%BE%E5%AE%9A%E4%B8%BA%E6%9F%90%E5%A4%A9
 %0A   
@@ -1496,16 +1496,22 @@
  // 
-%C2%B7%DD%B40%CA%BC3%D2%AA%D0%B42
+%E6%9C%88%E4%BB%BD%E4%BB%8E0%E5%BC%80%E5%A7%8B%EF%BC%8C%E8%AE%BE3%E6%9C%88%E8%A6%81%E5%86%992%E6%9C%88
 %0A%0A  
@@ -1511,32 +1511,34 @@
 %E5%86%992%E6%9C%88%0A%0A        // 
+%E6%9C%AC%E5%91%A8
 %0A        Calenda
@@ -1688,32 +1688,34 @@
 Y);%0A%0A        // 
+%E4%B8%8B%E5%91%A8
 %0A        Calenda
@@ -1881,16 +1881,18 @@
      // 
+%E4%B8%8A%E5%91%A8
 %0A       
@@ -2578,13 +2578,17 @@
  // 
-%C8%A1%D2%BB%DC%BF%CA%BC%D7%BC
+%E8%8E%B7%E5%8F%96%E8%BF%99%E4%B8%80%E5%91%A8%E5%BC%80%E5%A7%8B%E5%9F%BA%E5%87%86
 %0A   
@@ -2649,10 +2649,19 @@
  // 
-%C8%A1%D2%BB
+%E8%8E%B7%E5%8F%96%E5%BD%93%E5%A4%A9%E5%9C%A8%E8%BF%99%E4%B8%80%E5%91%A8%E5%86%85%E5%A4%A9%E6%95%B0
 %0A   

Update file encoding