Java 8时间处理-LocalDate

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BigBingtang/article/details/79281449

//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();



猜你喜欢

转载自blog.csdn.net/BigBingtang/article/details/79281449