Java 8時間處理 LocalDate

2021-08-15 11:31:12 字數 1010 閱讀 6755

//1.獲取當前時間

localdate defaultday = localdate.now();

//2.轉化指定年月日 

int startyear = 2018;

int startmonth= 2;

int startday= 7;

localdate defaultday = new localdate(startyear, startmonth, startday);

//+1個月

localdate = defaultday.plusmonths(1);

//格式化為指定格式

string yearmonth = itemtime.tostring("yyyy年mm月");

//獲取月份最後一天

int monthcount = itemtime.dayofmonth().withmaximumvalue().getdayofmonth();

//獲取年月

int year = itemtime.getyear();

int month = itemtime.getmonthofyear();

//是否在某日期之前

boolean dayisbefore = itemtime.isbefore(defaultday);

//是否在某日期之前

boolean dayisbefore = itemtime.isafter(defaultday);

// 獲取當月的第一天的星期

int withminiweek = itemtime.dayofmonth().withminimumvalue().getdayofweek();

// 獲取當月的最後一天的星期

int withmaxweek = itemtime.dayofmonth().withmaximumvalue().getdayofweek();

java8 時間類的使用

localdatetime 和localdate。獲取當前日期 localdate now localdate.now 獲取前一天 now.minusdays 1 獲取前一周 now.minusweeks 1 獲取前一月 now.minusmonths 1 獲取前一年 now.minusyears ...

Java 8 新日期和時間API

日期類 例 2018 02 08 只包含日期,不可變類,類定義 public final class localdate implements temporal,temporaladjuster,chronolocaldate,serializable 複製 localdate now locald...

JAVA 8日期處理類

以及格式化工具類 datetimeformatter chronofield 獲取時間值 chronounit 時間單位 localdate oneday localdate.now system.out.println oneday localdatetime twoday localdateti...