阅读背景:

Java8新特性 - 日期相关 - 日期加减

来源:互联网 
1. 日期相减
DateDiff.java
package corejava2.date;

import java.time.LocalDate;
import java.time.Period;

public class DateDiff {

	public static void main(String[] args) {
		/** The date at the end of the last century */
		LocalDate endofCentury = LocalDate.of(2000, 12, 31);
		LocalDate now = LocalDate.now();

		Period diff = Period.between(endofCentury, now);

		System.out.printf("The 21st century (up to %s) is %s old%n", now, diff);
		System.out.printf("The 21st century is %d years, %d months and %d days old",
				diff.getYears(), diff.getMonths(), diff.getDays());
	}
}
package corejava2.d



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: