本文整理汇总了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();
}