joda-time中Intervals,Duration,Period的使用
程序员文章站
2022-03-09 21:45:50
...
先贴代码,之后再补理解:
package net.icsoc.cti.report;
import org.joda.time.*;
/*******************************************************************************
* 版权信息:北京中通天鸿武汉分公司
* @author xuchang
* Copyright: Copyright (c) 2007北京中通天鸿武汉分公司,Inc.All Rights Reserved.
* Description:
******************************************************************************/
public class Test {
public static void main(String[] args) {
/**
* Intervals
*/
System.out.println("Intervals=============================");
// yearMoth
YearMonth yearMonth = new YearMonth();
//当前失去的Intervals
System.out.println(yearMonth.toInterval());
//MothDay
YearMonthDay yearMonthDay = new YearMonthDay();
System.out.println(yearMonthDay.toInterval());
System.out.println(yearMonthDay.toInterval(DateTimeZone.UTC));
System.out.println(Interval.parse("2018-08-01/2018-08-30"));
/**
* Duration
*/
System.out.println("Duration=========================");
System.out.println(Duration.standardDays(1L));
System.out.println(Duration.standardHours(100));
/**
* Period
*/
System.out.println("Period=========================");
//使用Second直接获取Period
System.out.println(Seconds.seconds(1));
//使用Minutes直接获取Period
System.out.println(Minutes.minutes(1));
//使用Hours直接获取Period
System.out.println("3" + Hours.hours(1));
//使用Hours直接获取Period
System.out.println(Days.days(1));
System.out.println(Months.months(1));
System.out.println(Weeks.weeks(1));
System.out.println(Years.years(2).toString());
System.out.println(Period.days(1));
System.out.println(Period.minutes(15));
System.out.println(Period.weeks(1));
}
}
结果集
Intervals=============================
2018-08-01T00:00:00.000+08:00/2018-09-01T00:00:00.000+08:00
2018-08-23T00:00:00.000+08:00/2018-08-24T00:00:00.000+08:00
2018-08-23T00:00:00.000Z/2018-08-24T00:00:00.000Z
2018-08-01T00:00:00.000+08:00/2018-08-30T00:00:00.000+08:00
Duration=========================
PT86400S
PT360000S
Period=========================
PT1S
PT1M
3PT1H
P1D
P1M
P1W
P2Y
P1D
PT15M
P1W
Process finished with exit code 0
推荐阅读
-
Java日期时间API系列9-----Jdk8中java.time包中的新的日期时间API类的Period和Duration的区别
-
浅谈JDK8中的Duration Period和ChronoUnit
-
Java日期时间API系列9-----Jdk8中java.time包中的新的日期时间API类的Period和Duration的区别
-
Java8中使用以下类计算日期时间差:Period、Duration、ChronoUnit
-
Java8中使用以下类计算日期时间差:Period、Duration、ChronoUnit
-
joda-time中Intervals,Duration,Period的使用
-
浅谈JDK8中的Duration Period和ChronoUnit