org.joda.time.YearMonthDay类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(115)

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

YearMonthDay介绍

[英]YearMonthDay is an immutable partial supporting the year, monthOfYear and dayOfMonth fields.

NOTE: This class only supports the three fields listed above. Thus, you cannot query the dayOfWeek or centuryOfEra fields for example. The new LocalDate class removes this restriction.

Calculations on YearMonthDay are performed using a Chronology. This chronology is set to be in the UTC time zone for all calculations.

Each individual field can be queried in two ways:

  • getMonthOfYear()

  • monthOfYear().get()
    The second technique also provides access to other useful methods on the field:

  • numeric value - monthOfYear().get()

  • text value - monthOfYear().getAsText()

  • short text value - monthOfYear().getAsShortText()

  • maximum/minimum values - monthOfYear().getMaximumValue()

  • add/subtract - monthOfYear().addToCopy()

  • set - monthOfYear().setCopy()

YearMonthDay is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
[中]YearMonthDay是一个不可变的部分,支持year、monthOfYear和dayOfMonth字段。
注意:这个类只支持上面列出的三个字段。因此,例如,您不能查询dayOfWeek或centuryOfEra字段。新的LocalDate类删除了这个限制。
YearMonthDay的计算使用年表进行。对于所有计算,该年表设置为UTC时区。
可以通过两种方式查询每个字段:

  • getMonthOfYear()
  • monthOfYear().get()
    第二种技术还提供了现场其他有用方法:
    *数值-monthOfYear().get()
    *文本值-monthOfYear().getAsText()
    *短文本值-monthOfYear().getAsShortText()
    *最大值/最小值-monthOfYear().getMaximumValue()
    *加/减-monthOfYear().addToCopy()
    *套装-monthOfYear().setCopy()
    YearMonthDay是线程安全且不可变的,前提是年表也是。提供的所有标准时序类都是线程安全且不可变的。

代码示例

代码示例来源:origin: joda-time/joda-time

/**
 * Returns a copy of this date with the specified field set to a new value.
 * <p>
 * For example, if the field type is <code>dayOfMonth</code> then the day
 * would be changed in the returned instance.
 * <p>
 * These three lines are equivalent:
 * <pre>
 * YearMonthDay updated = ymd.withField(DateTimeFieldType.dayOfMonth(), 6);
 * YearMonthDay updated = ymd.dayOfMonth().setCopy(6);
 * YearMonthDay updated = ymd.property(DateTimeFieldType.dayOfMonth()).setCopy(6);
 * </pre>
 *
 * @param fieldType  the field type to set, not null
 * @param value  the value to set
 * @return a copy of this instance with the field set
 * @throws IllegalArgumentException if the value is null or invalid
 */
public YearMonthDay withField(DateTimeFieldType fieldType, int value) {
  int index = indexOfSupported(fieldType);
  if (value == getValue(index)) {
    return this;
  }
  int[] newValues = getValues();
  newValues = getField(index).set(this, index, newValues, value);
  return new YearMonthDay(this, newValues);
}

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this object to a DateMidnight in the default time zone.
 *
 * @return the DateMidnight instance in the default zone
 */
public DateMidnight toDateMidnight() {
  return toDateMidnight(null);
}

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this object to a LocalDate with the same date and chronology.
 *
 * @return a LocalDate with the same date and chronology
 * @since 1.3
 */
public LocalDate toLocalDate() {
  return new LocalDate(getYear(), getMonthOfYear(), getDayOfMonth(), getChronology());
}

代码示例来源:origin: joda-time/joda-time

/**
 * Returns a copy of this date with the day of month field updated.
 * <p>
 * YearMonthDay is immutable, so there are no set methods.
 * Instead, this method returns a new instance with the value of
 * day of month changed.
 *
 * @param dayOfMonth  the day of month to set
 * @return a copy of this object with the field set
 * @throws IllegalArgumentException if the value is invalid
 * @since 1.3
 */
public YearMonthDay withDayOfMonth(int dayOfMonth) {
  int[] newValues = getValues();
  newValues = getChronology().dayOfMonth().set(this, DAY_OF_MONTH, newValues, dayOfMonth);
  return new YearMonthDay(this, newValues);
}

代码示例来源:origin: joda-time/joda-time

return this;
int[] newValues = getValues();
for (int i = 0; i < period.size(); i++) {
  DurationFieldType fieldType = period.getFieldType(i);
  int index = indexOf(fieldType);
  if (index >= 0) {
    newValues = getField(index).add(this, index, newValues,
        FieldUtils.safeMultiply(period.getValue(i), scalar));
return new YearMonthDay(this, newValues);

代码示例来源:origin: joda-time/joda-time

/**
 * Sets this field in a copy of the YearMonthDay.
 * <p>
 * The YearMonthDay attached to this property is unchanged by this call.
 * Instead, a new instance is returned.
 * 
 * @param value  the value to set the field in the copy to
 * @return a copy of the YearMonthDay with the field value changed
 * @throws IllegalArgumentException if the value isn't valid
 */
public YearMonthDay setCopy(int value) {
  int[] newValues = iYearMonthDay.getValues();
  newValues = getField().set(iYearMonthDay, iFieldIndex, newValues, value);
  return new YearMonthDay(iYearMonthDay, newValues);
}

代码示例来源:origin: FenixEdu/fenixedu-academic

public void setStateDate(final YearMonthDay ymd) {
  if (ymd == null) {
    setStateDateTime(null);
    return;
  }
  setStateDateTime(new YearMonthDay().equals(ymd) ? ymd.toDateTimeAtCurrentTime() : ymd.toDateTimeAtMidnight());
}

代码示例来源:origin: FenixEdu/fenixedu-academic

public ViewEventSpaceOccupationsBean(YearMonthDay day, Space allocatableSpace) {
  setAllocatableSpace(allocatableSpace);
  if (day != null) {
    setYear(new Partial(DateTimeFieldType.year(), day.getYear()));
    setMonth(new Partial(DateTimeFieldType.monthOfYear(), day.getMonthOfYear()));
    YearMonthDay monday = day.toDateTimeAtMidnight().withDayOfWeek(MONDAY_IN_JODA_TIME).toYearMonthDay();
    if ((monday.getMonthOfYear() < day.getMonthOfYear()) || (monday.getYear() < day.getYear())) {
      monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
    }
    setDay(monday);
  }
}

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this partial to a full datetime using the default time zone
 * setting the date fields from this instance and the time fields from
 * the current time.
 *
 * @return this date as a datetime with the time as the current time
 */
public DateTime toDateTimeAtCurrentTime() {
  return toDateTimeAtCurrentTime(null);
}

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this object to a DateTime using a TimeOfDay to fill in the
 * missing fields and using the default time zone.
 * This instance is immutable and unaffected by this method call.
 * <p>
 * The resulting chronology is determined by the chronology of this
 * YearMonthDay plus the time zone.
 * The chronology of the time is ignored - only the field values are used.
 *
 * @param time  the time of day to use, null means current time
 * @return the DateTime instance
 */
public DateTime toDateTime(TimeOfDay time) {
  return toDateTime(time, null);
}

代码示例来源:origin: FenixEdu/fenixedu-academic

protected YearMonthDay getStartDate() {
  final ExecutionInterval interval = getCandidacyExecutionInterval();
  final YearMonthDay today = new YearMonthDay();
  return interval.isCurrent() && interval.getAcademicInterval().contains(today.toDateMidnight()) ? today : interval
      .getBeginDateYearMonthDay();
}

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this YearMonthDay to a full datetime at midnight using the
 * default time zone.
 *
 * @return this date as a datetime at midnight
 */
public DateTime toDateTimeAtMidnight() {
  return toDateTimeAtMidnight(null);
}

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this object to a <code>YearMonthDay</code> using the
 * same millis and chronology.
 * 
 * @return a YearMonthDay using the same millis and chronology
 * @deprecated Use LocalDate instead of YearMonthDay
 */
@Deprecated
public YearMonthDay toYearMonthDay() {
  return new YearMonthDay(getMillis(), getChronology());
}

代码示例来源:origin: FenixEdu/fenixedu-academic

@Override
public List<Interval> getEventSpaceOccupationIntervals(YearMonthDay startDateToSearch, YearMonthDay endDateToSearch) {
  List<Interval> result = new ArrayList<Interval>();
  Collection<LessonInstance> lessonInstances = getLessonInstancesSet();
  DateTime startDateTime = startDateToSearch != null ? startDateToSearch.toDateTimeAtMidnight() : null;
  DateTime endDateTime = endDateToSearch != null ? endDateToSearch.toDateTime(new TimeOfDay(23, 59, 59)) : null;
  for (LessonInstance lessonInstance : lessonInstances) {
    if (startDateTime == null
        || (!lessonInstance.getEndDateTime().isBefore(startDateTime) && !lessonInstance.getBeginDateTime().isAfter(
            endDateTime))) {
      result.add(new Interval(lessonInstance.getBeginDateTime(), lessonInstance.getEndDateTime()));
    }
  }
  return result;
}

代码示例来源:origin: joda-time/joda-time

/**
 * Gets the field that this property uses.
 * 
 * @return the field
 */
public DateTimeField getField() {
  return iYearMonthDay.getField(iFieldIndex);
}

代码示例来源:origin: FenixEdu/fenixedu-academic

private YearMonthDay getValidEndDate(YearMonthDay endDate) {
  YearMonthDay lessonEnd =
      endDate.toDateTimeAtMidnight().withDayOfWeek(getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat()).toYearMonthDay();
  if (lessonEnd.isAfter(endDate)) {
    lessonEnd = lessonEnd.minusDays(NUMBER_OF_DAYS_IN_WEEK);
  }
  return lessonEnd;
}

代码示例来源:origin: joda-time/joda-time

/**
 * Converts this partial to a full datetime using the specified time zone
 * setting the date fields from this instance and the time fields from
 * the current time.
 * <p>
 * This method uses the chronology from this instance plus the time zone
 * specified.
 *
 * @param zone  the zone to use, null means default
 * @return this date as a datetime with the time as the current time
 */
public DateTime toDateTimeAtCurrentTime(DateTimeZone zone) {
  Chronology chrono = getChronology().withZone(zone);
  long instantMillis = DateTimeUtils.currentTimeMillis();
  long resolved = chrono.set(this, instantMillis);
  return new DateTime(resolved, chrono);
}

代码示例来源:origin: joda-time/joda-time

/**
 * Returns a copy of this date with the year field updated.
 * <p>
 * YearMonthDay is immutable, so there are no set methods.
 * Instead, this method returns a new instance with the value of
 * year changed.
 *
 * @param year  the year to set
 * @return a copy of this object with the field set
 * @throws IllegalArgumentException if the value is invalid
 * @since 1.3
 */
public YearMonthDay withYear(int year) {
  int[] newValues = getValues();
  newValues = getChronology().year().set(this, YEAR, newValues, year);
  return new YearMonthDay(this, newValues);
}

代码示例来源:origin: JodaOrg/joda-time

return this;
int[] newValues = getValues();
for (int i = 0; i < period.size(); i++) {
  DurationFieldType fieldType = period.getFieldType(i);
  int index = indexOf(fieldType);
  if (index >= 0) {
    newValues = getField(index).add(this, index, newValues,
        FieldUtils.safeMultiply(period.getValue(i), scalar));
return new YearMonthDay(this, newValues);

代码示例来源:origin: JodaOrg/joda-time

/**
 * Sets this field in a copy of the YearMonthDay.
 * <p>
 * The YearMonthDay attached to this property is unchanged by this call.
 * Instead, a new instance is returned.
 * 
 * @param value  the value to set the field in the copy to
 * @return a copy of the YearMonthDay with the field value changed
 * @throws IllegalArgumentException if the value isn't valid
 */
public YearMonthDay setCopy(int value) {
  int[] newValues = iYearMonthDay.getValues();
  newValues = getField().set(iYearMonthDay, iFieldIndex, newValues, value);
  return new YearMonthDay(iYearMonthDay, newValues);
}

相关文章