本文整理匯總了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()));
}
示例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()));
}
示例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());
}
示例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;
}
示例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();
}