博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
threeten-extra使用实例
阅读量:7009 次
发布时间:2019-06-28

本文共 1881 字,大约阅读时间需要 6 分钟。

  hot3.png

threeten-extra是一个基于java8的java.time的扩展包,本文简单介绍一下threeten-extra的使用实例。

maven

org.threeten
threeten-extra
1.2

实例

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);    @Test    public void testAmPm(){        System.out.println(AmPm.from(LocalTime.now()));    }    @Test    public void testDayOfMonth(){        System.out.println(DayOfMonth.from(LocalDate.now()));    }    @Test    public void testDayOfYear(){        System.out.println(DayOfYear.from(LocalDate.now()));    }    @Test    public void testYears(){        System.out.println(Years.between(first,second));    }    @Test    public void testMonths(){        System.out.println(Months.between(first,second));    }    @Test    public void testWeeks(){        System.out.println(Weeks.between(first,second));    }    @Test    public void testDays(){        System.out.println(Days.between(LocalDate.parse("2017-08-01"),LocalDate.parse("2017-08-03")));    }    @Test    public void testHours(){        System.out.println(Hours.between(first,second).getAmount());    }    @Test    public void testMinutes(){        System.out.println(Minutes.between(first,second));    }    @Test    public void testSeconds(){        System.out.println(Seconds.between(first,second));    }    @Test    public void testTemporals(){        System.out.println(first.with(Temporals.previousWorkingDay()));        System.out.println(first.with(Temporals.nextWorkingDay()));    }    @Test    public void testDuration(){        System.out.println(PeriodDuration.between(first,second).getPeriod());        System.out.println(PeriodDuration.between(first,second).getDuration());    }

doc

转载于:https://my.oschina.net/go4it/blog/1525177

你可能感兴趣的文章