进阶day01-Calendar里面的get方法
This commit is contained in:
@@ -7,12 +7,24 @@ import java.util.Calendar;
|
|||||||
Calendar类是一个抽象类,必须使用它的子类但是该类比较特殊.使用本身的静态方法获取一个日历对象
|
Calendar类是一个抽象类,必须使用它的子类但是该类比较特殊.使用本身的静态方法获取一个日历对象
|
||||||
|
|
||||||
static Calendar getInstance() 使用默认时区和区域设置获取日历。
|
static Calendar getInstance() 使用默认时区和区域设置获取日历。
|
||||||
|
--------------------------------------------------------------------------
|
||||||
|
Calendar里面的get方法
|
||||||
|
public int get(int field) :返回给定日历字段的值。
|
||||||
|
|
||||||
|
注意:在api中直接输入1,2,3字段值,代码阅读性不强,所以在当前类中通常会定义一些相关的静态的常量来表示指定的内容
|
||||||
*/
|
*/
|
||||||
public class Demo08 {
|
public class Demo08 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//使用类方法(静态方法)
|
//使用类方法(静态方法)
|
||||||
Calendar calendar = Calendar.getInstance();//多态,抽象父类引用指向子类对象
|
Calendar calendar = Calendar.getInstance();//多态,抽象父类引用指向子类对象
|
||||||
System.out.println(calendar);//calendar中保存的是地址,Calendar重写了toString
|
System.out.println(calendar);//calendar中保存的是地址,Calendar重写了toString
|
||||||
|
|
||||||
|
System.out.println(calendar.get(1));
|
||||||
|
System.out.println(calendar.get(Calendar.YEAR));
|
||||||
|
System.out.println(calendar.get(Calendar.MONTH));
|
||||||
|
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
|
||||||
|
System.out.println(calendar.get(Calendar.MINUTE));
|
||||||
|
System.out.println(calendar.get(Calendar.SECOND));
|
||||||
|
System.out.println(calendar.get(Calendar.HOUR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user