当前位置: 首页>>代码示例>>Java>>正文


Java PeriodType.yearMonthDay方法代码示例

本文整理汇总了Java中org.joda.time.PeriodType.yearMonthDay方法的典型用法代码示例。如果您正苦于以下问题:Java PeriodType.yearMonthDay方法的具体用法?Java PeriodType.yearMonthDay怎么用?Java PeriodType.yearMonthDay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.joda.time.PeriodType的用法示例。


在下文中一共展示了PeriodType.yearMonthDay方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testToPeriodWithLowClosedHighOpenDate

import org.joda.time.PeriodType; //导入方法依赖的package包/类
@Test
public void testToPeriodWithLowClosedHighOpenDate() {
    PointInTime start = new PointInTime(2000, 1, 2);
    PointInTime stop = new PointInTime(2001, 1, 1);
    Period expected = new Period(start.promote().getLow(), stop.promote().getHigh().subtractMilliseconds(1));
    Period actual = new IntervalOfTime(start, stop).toPeriod();
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
    expected = new Period(start.promote().getLow(), stop.promote().getHigh().subtractMilliseconds(1), PeriodType.yearMonthDay());
    actual = new IntervalOfTime(start, stop).toPeriod(PeriodType.yearMonthDay());
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:IntervalOfTimeTest.java

示例2: testToPeriodWithLowOpenHighClosedDate

import org.joda.time.PeriodType; //导入方法依赖的package包/类
@Test
public void testToPeriodWithLowOpenHighClosedDate() {
    PointInTime start = new PointInTime(2000, 1, 2);
    PointInTime stop = new PointInTime(2001, 1, 1);
    IntervalOfTime iot = stop.promote();
    PointInTime iota = iot.getHigh();
    Period expected = new Period(start.promote().getLow().addMilliseconds(1), iota.subtractMilliseconds(1));
    Period actual = new IntervalOfTime(start, stop, false, true, false).toPeriod();
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
    expected = new Period(start.promote().getLow().addMilliseconds(1), iota.subtractMilliseconds(1), PeriodType.yearMonthDay());
    actual = new IntervalOfTime(start, stop, false, true, false).toPeriod(PeriodType.yearMonthDay());
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:26,代码来源:IntervalOfTimeTest.java

示例3: calculateAge

import org.joda.time.PeriodType; //导入方法依赖的package包/类
public static Age calculateAge(Calendar birthDate) {
	LocalDate birthdate = LocalDate.fromCalendarFields(birthDate);
	LocalDate now = new LocalDate();                    //Today's date
	Period period = new Period(birthdate, now, PeriodType.yearMonthDay());
	
	return new Age(period.getDays(),period.getMonths(),period.getYears());
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:8,代码来源:AgeCalculator.java

示例4: difference

import org.joda.time.PeriodType; //导入方法依赖的package包/类
public DateDifference difference(final LocalDate from, final LocalDate to) {
	final Period p = new Period(from, to, PeriodType.yearMonthDay());

	final DateDifference result = new DateDifference(p.getYears(),
			p.getMonths(), p.getDays());
	return result;
}
 
开发者ID:rduerig,项目名称:nansai,代码行数:8,代码来源:DateDifferenceCalculator.java

示例5: getDifferenceOfDatesInYears

import org.joda.time.PeriodType; //导入方法依赖的package包/类
/**
 * Returns difference, in years, between given date and today.
 *
 * @param startDate  the date from which year are counted
 * @return difference in years
 */
public static int getDifferenceOfDatesInYears(Date startDate) {
    Period period = new Period(newDate(startDate), today(), PeriodType.yearMonthDay());
    return period.getYears();
}
 
开发者ID:motech,项目名称:motech,代码行数:11,代码来源:DateUtil.java


注:本文中的org.joda.time.PeriodType.yearMonthDay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。