public static void main(String[] args) {
function();
function_01();
function_02();
function_03();
}
/**
* Date date = c.getTime()
*/
private static void function_03() {
Calendar c = Calendar.getInstance();
Date date = c.getTime();
System.out.println(date);
}
/**
* c.add(Calendar.DAY_OF_MONTH, -3)
*/
private static void function_02() {
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, -3);
System.out.println(
c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");
}
/**
* c.set(2024, 4, 8)
*/
private static void function_01() {
Calendar c = Calendar.getInstance();
c.set(2024, 4, 8);
System.out.println(
c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");
}
/**
* int year = c.get(Calendar.YEAR);
* int month = c.get(Calendar.MONTH)+1;
* int day = c.get(Calendar.DAY_OF_MONTH);
*/
private static void function() {
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
int day = c.get(Calendar.DAY_OF_MONTH);
System.out.println(year + "年" + month + "月" + day + "日");
}
Calendar类的一些函数
最新推荐文章于 2023-01-04 13:33:58 发布