Calendar類處理

Calendar calendar = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        //calendar.setTime(new Date());
        Date temp = formatter.parse("2016-9-09");
        calendar.setTime(temp);
        
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int date = calendar.get(Calendar.DATE);
        String yearString = month + 1 > 12 ? String.valueOf(year+1):String.valueOf(year);
        String monthString = month <= 9 ? "0" + String.valueOf(month+1) :String.valueOf(month+1);
        String dateString = date <= 9 ? "0" + String.valueOf(date) :String.valueOf(date);
        System.out.println(year);
        System.out.println(month);
        System.out.println("=====");
        System.out.println(yearString);
        System.out.println(monthString);
        System.out.println(dateString);
        System.out.println("=====");orm

相關文章
相關標籤/搜索