當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。