threeten-extra使用实例
生活随笔
收集整理的這篇文章主要介紹了
threeten-extra使用实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
序
threeten-extra是一個基于java8的java.time的擴展包,本文簡單介紹一下threeten-extra的使用實例。
maven
<dependency><groupId>org.threeten</groupId><artifactId>threeten-extra</artifactId><version>1.2</version></dependency>實例
獲取日期的年、月、周、天、時、分
LocalDateTime first = LocalDateTime.parse("2017-07-03T10:15:30", DateTimeFormatter.ISO_DATE_TIME); LocalDateTime second = LocalDateTime.parse("2011-08-08T12:15:10", DateTimeFormatter.ISO_DATE_TIME);@Testpublic void testYears(){System.out.println(Years.between(first,second));}@Testpublic void testMonths(){System.out.println(Months.between(first,second));}@Testpublic void testWeeks(){System.out.println(Weeks.between(first,second));}@Testpublic void testDays(){System.out.println(Days.between(LocalDate.parse("2017-08-01"),LocalDate.parse("2017-08-03")));}@Testpublic void testHours(){System.out.println(Hours.between(first,second).getAmount());}@Testpublic void testMinutes(){System.out.println(Minutes.between(first,second));}@Testpublic void testSeconds(){System.out.println(Seconds.between(first,second));}獲取am或pm時間
@Testpublic void testAmPm(){System.out.println(AmPm.from(LocalTime.now()));}獲取月或年中的天數
@Testpublic void testDayOfMonth(){System.out.println(DayOfMonth.from(LocalDate.now()));}@Testpublic void testDayOfYear(){System.out.println(DayOfYear.from(LocalDate.now()));}獲取上/下一工作日
@Testpublic void testTemporals(){System.out.println(first.with(Temporals.previousWorkingDay()));System.out.println(first.with(Temporals.nextWorkingDay()));}獲取時間距離
@Testpublic void testDuration(){System.out.println(PeriodDuration.between(first,second).getPeriod());System.out.println(PeriodDuration.between(first,second).getDuration());}doc
threeten-extra
總結
以上是生活随笔為你收集整理的threeten-extra使用实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Distcp 分布式拷贝
- 下一篇: 直升机和固定翼实操期末考试