首页 > 其他分享 >Calendar类的习题

Calendar类的习题

时间:2023-03-21 15:31:37浏览次数:30  
标签:get int Calendar ca static 习题 public


由于Calendar是抽象类,不能实例化,所以利用子类对象进行调用方法。

package Calender_study;

import java.util.Calendar;

public class calender_t1 {
public static void main(String[] args) {

Calendar ca = Calendar.getInstance();
Calendar_print(ca);

}

public static void Calendar_print(Calendar ca) {
int year = ca.get(Calendar.YEAR);
int month = ca.get(Calendar.MONTH);
System.out.println("今天是" + year + "年" + (month + 1) + "月" + ca.get(Calendar.DATE) + "日,星期" +getIndexArr(ca.get(Calendar.DAY_OF_WEEK)) + ",是今年的第" + ca.get(Calendar.DAY_OF_YEAR) + "天");
ca.set(Calendar.YEAR, 2008);
}

public static String getIndexArr(int i) {
String s[] = {"", "日", "一", "二", "三", "四", "五", "六"};
return s[i];
}
}

标签:get,int,Calendar,ca,static,习题,public
From: https://blog.51cto.com/u_15738297/6140256

相关文章