关于ChronoUnit工具类的几个小用法
jdk1.8给出的解释:

常见用法:
@Test
public void testChromoUnitsPlus() {
//Get the current date
LocalDate today = LocalDate.now();
System.out.println("Current date: " + today);
//add 1 week to the current date
LocalDate nextWeek = today.plus(1, ChronoUnit.WEEKS);
System.out.println("Next week: " + nextWeek);
//add 1 month to the current date
LocalDate nextMonth = today.plus(1, ChronoUnit.MONTHS);
System.out.println("Next month: " + nextMonth);
//add 1 year to the current date
LocalDate nextYear = today.plus(1, ChronoUnit.YEARS);
System.out.println("Next year: " + nextYear);
//add 10 years to the current date
LocalDate nextDecade = today.plus(1, ChronoUnit.DECADES);
System.out.println("Date after ten year: " + nextDecade);
}
输出:
Current date: 2021-12-09
Next week: 2021-12-16
Next month: 2022-01-09
Next year: 2022-12-09
Date after ten year: 2031-12-09
between用法
int lastDateTime = (int) ChronoUnit.HOURS.between(createTime, localDateTime);
//between取createTime和localDateTime间的差值,返回值为long,这里转化了一下
私の名は「吉良吉影」、年齢33歳。
自宅は杜王町北東部の別荘地帯にあり、結婚はしていない。
仕事は「亀友ーチェーン店」の会社員で、毎日遅くとも夜8時までには帰宅する。
タバコは吸わない、酒は嗜む程度。
夜十一時には床につき、必ず8時間は睡眠をとるようにしている。
寝る前に暖かいミルクを飲み、二十分ほどのストレッチで体をほぐしてから床に就く(つく)と、ほとんど朝まで熟睡さ。
赤ん坊のように疲労やストレスを残さずに、朝目を覚ませるんだ、健康診断でも異常なしと言われたよ。

浙公网安备 33010602011771号