s-day01--LocalDate的基本使用(代替Calender)--1
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.inmind.jdk8_time04;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/*
|
||||
LocalDate的基本使用(代替Calender)
|
||||
*/
|
||||
public class Demo08 {
|
||||
public static void main(String[] args) {
|
||||
//1.获取本地日期对象,(时间不可变)
|
||||
LocalDate ld = LocalDate.now();
|
||||
System.out.println(ld);//LocalDate重写了toString
|
||||
|
||||
//2.获取日期对象的信息
|
||||
int year = ld.getYear();//年
|
||||
System.out.println(year);
|
||||
int monthValue = ld.getMonthValue();//月
|
||||
System.out.println(monthValue);
|
||||
int day = ld.getDayOfMonth();//日
|
||||
System.out.println(day);
|
||||
|
||||
// 3、直接修改某个信息: withYear、withMonth、withDayOfMonth、withDayOfYear
|
||||
LocalDate ld1 = ld.withYear(2099);
|
||||
System.out.println(ld1);
|
||||
LocalDate ld2 = ld.withMonth(12);
|
||||
System.out.println(ld2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user