[Java] Calendar to get year, month, day, time

Reprinted from: https://www.cnblogs.com/longYou/p/6382399.html
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); //Get the time of East Eighth District

        //get year
        int year = c.get(Calendar.YEAR);
        //Get the month, 0 means January
        int month = c.get(Calendar.MONTH) + 1;
        //get the current day
        int day = c.get(Calendar.DAY_OF_MONTH);
        //Get the minimum number of days in this month
        int first = c.getActualMinimum(Calendar.DAY_OF_MONTH);
        //Get the maximum number of days in this month
        int last = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        //get current hour
        int time = c.get(Calendar.HOUR_OF_DAY);
        //get the current minute
        int min = c.get(Calendar.MINUTE);
        //get the current second
        int sec = c.get(Calendar.SECOND);                                                     

        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String curDate = s.format(c.getTime()); //current date
        System.out.println("当前时间:" + year + "-" + month + "-" + day + " " + time + ":" + min + ":" + sec);
        System.out.println("First and last day: " + first + "," + last);
        System.out.println("Current date: " + curDate);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325498370&siteId=291194637