手记

使用Calendar类显示时间

package com.java1234.chap05.sec01;

import java.util.Calendar;
/**
 * 使用Calendar类显示时间
 * @author dell
 *
 */
public class TestCalendar {

    public static void main(String[] args) {

        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        System.out.println(year);
        int month = calendar.get(Calendar.MONTH)+1;
        System.out.println(month);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(day);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        System.out.println(hour);
        int minute = calendar.get(Calendar.MINUTE);
        System.out.println(minute);
        int second = calendar.get(Calendar.SECOND);
        System.out.println(year+"年"+month+"月"+day+"日  "+hour+"时"+minute+"分"+
        second+"秒");
    }
}
0人推荐
随时随地看视频
慕课网APP