Calendar应用实例
package com.czie.iot1913.lps.Date;
import java.util.Calendar;
/**
* FileName: CalendarTest01
* Author: lps
* Date: 2022/3/23 20:38
* Sign:刘品水 Q:1944900433
*/
public class CalendarTest01 {
public static void main(String[] args) {
//Calendar是一个抽象类
Calendar c = Calendar.getInstance();
System.out.println(c);
//calendar返回月份是从0开始 所以需要加1
System.out.println("年:" + c.get(Calendar.YEAR));
System.out.println("月:" + (c.get(Calendar.MONTH) + 1));
System.out.println("日:" + c.get(Calendar.DAY_OF_MONTH));
System.out.println("时:" + c.get(Calendar.HOUR));
System.out.println("分:" + c.get(Calendar.MINUTE));
System.out.println("秒:" + c.get(Calendar.SECOND));
System.out.println("========");
System.out.println(c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DATE)
+ "," + c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND));
}
}