org.joda.time.DateTime.yearOfEra()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(341)

本文整理了Java中org.joda.time.DateTime.yearOfEra()方法的一些代码示例,展示了DateTime.yearOfEra()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.yearOfEra()方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:yearOfEra

DateTime.yearOfEra介绍

[英]Get the year of era property which provides access to advanced functionality.
[中]获取“纪年”属性,该属性提供对高级功能的访问。

代码示例

代码示例来源:origin: stackoverflow.com

public static DateTime dateTimeFloor(DateTime dt, Period p) {
  if (p.getYears() != 0) {
    return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
  } else if (p.getMonths() != 0) {
    return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
  } else if (p.getWeeks() != 0) {
    return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
  } else if (p.getDays() != 0) {
    return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
  } else if (p.getHours() != 0) {
    return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
  } else if (p.getMinutes() != 0) {
    return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
  } else if (p.getSeconds() != 0) {
    return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
  }
  return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

代码示例来源:origin: org.rhq/rhq-cassandra-schema

private DateTime getTimeSlice(DateTime dt, Duration duration) {
  Period p = duration.toPeriod();
  if (p.getYears() != 0) {
    return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
  } else if (p.getMonths() != 0) {
    return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
  } else if (p.getWeeks() != 0) {
    return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
  } else if (p.getDays() != 0) {
    return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
  } else if (p.getHours() != 0) {
    return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
  } else if (p.getMinutes() != 0) {
    return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
  } else if (p.getSeconds() != 0) {
    return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
  }
  return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

代码示例来源:origin: hawkular/hawkular-metrics

public static DateTime getTimeSlice(DateTime dt, Duration duration) {
  Period p = duration.toPeriod();
  if (p.getYears() != 0) {
    return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
  } else if (p.getMonths() != 0) {
    return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
  } else if (p.getWeeks() != 0) {
    return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
  } else if (p.getDays() != 0) {
    return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
  } else if (p.getHours() != 0) {
    return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
  } else if (p.getMinutes() != 0) {
    return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
  } else if (p.getSeconds() != 0) {
    return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
  }
  return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

代码示例来源:origin: org.rhq/rhq-cassandra-schema

protected static DateTime getTimeSlice(DateTime dt, Duration duration) {
  Period p = duration.toPeriod();
  if (p.getYears() != 0) {
    return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
  } else if (p.getMonths() != 0) {
    return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
  } else if (p.getWeeks() != 0) {
    return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
  } else if (p.getDays() != 0) {
    return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
  } else if (p.getHours() != 0) {
    return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
  } else if (p.getMinutes() != 0) {
    return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
  } else if (p.getSeconds() != 0) {
    return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
  }
  return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

相关文章

DateTime类方法