本文整理了Java中org.threeten.bp.LocalDate.get()
方法的一些代码示例,展示了LocalDate.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.get()
方法的具体详情如下:
包路径:org.threeten.bp.LocalDate
类名称:LocalDate
方法名:get
[英]Gets the value of the specified field from this date as an int.
This queries this date for the value for the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField then the query is implemented here. The #isSupported(TemporalField) will return valid values based on this date, except EPOCH_DAY and EPOCH_MONTHwhich are too large to fit in an int and throw a DateTimeException. All other ChronoField instances will throw a DateTimeException.
If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom(TemporalAccessor)passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.
[中]获取从此日期起指定字段的值,该值为int。
此操作将在此日期查询指定字段的值。返回的值将始终在字段的有效值范围内。如果由于字段不受支持或其他原因而无法返回值,则会引发异常。
如果该字段是一个ChronoField,则在此处实现查询。#isSupported(TemporalField)将基于此日期返回有效值,但EPOCH_DAY和EPOCH_month除外,这两个值太大,无法放入int并引发DateTimeException。所有其他ChronoField实例将引发DateTimeException。
如果字段不是ChronoField,则通过调用TemporalField获得此方法的结果。getFrom(临时Accessor)将此作为参数传递。是否可以获得该值以及该值表示的内容由字段决定。
代码示例来源:origin: prolificinteractive/material-calendarview
private int getWeekCountBasedOnMode() {
int weekCount = calendarMode.visibleWeeksCount;
final boolean isInMonthsMode = calendarMode.equals(CalendarMode.MONTHS);
if (isInMonthsMode && mDynamicHeightEnabled && adapter != null && pager != null) {
final LocalDate cal = adapter.getItem(pager.getCurrentItem()).getDate();
final LocalDate tempLastDay = cal.withDayOfMonth(cal.lengthOfMonth());
weekCount = tempLastDay.get(WeekFields.of(firstDayOfWeek, 1).weekOfMonth());
}
return showWeekDays ? weekCount + DAY_NAMES_ROW : weekCount;
}
代码示例来源:origin: SouthernBox/NestedCalendar
@Override
public void onDateSelected(@NonNull MaterialCalendarView widget,
@NonNull CalendarDay calendarDay,
boolean selected) {
LocalDate localDate = calendarDay.getDate();
WeekFields weekFields = WeekFields.of(Locale.getDefault());
calendarBehavior.setWeekOfMonth(localDate.get(weekFields.weekOfMonth()));
if (selected) {
dayOfWeek = localDate.getDayOfWeek().getValue();
dayOfMonth = localDate.getDayOfMonth();
}
}
});
代码示例来源:origin: SouthernBox/NestedCalendar
@Override
public void onMonthChanged(MaterialCalendarView widget, CalendarDay calendarDay) {
if (calendarBehavior.getCalendarMode() == null) {
return;
}
LocalDate localDate = calendarDay.getDate();
LocalDate newDate;
if (calendarBehavior.getCalendarMode() == CalendarMode.WEEKS) {
newDate = localDate.plusDays(dayOfWeek - 1);
dayOfMonth = newDate.getDayOfMonth();
} else {
int monthDays = localDate.getMonth().length(localDate.isLeapYear());
if (dayOfMonth > monthDays) {
dayOfMonth = monthDays;
}
newDate = localDate.plusDays(dayOfMonth - 1);
dayOfWeek = newDate.getDayOfWeek().getValue();
}
widget.setSelectedDate(newDate);
WeekFields weekFields = WeekFields.of(Locale.getDefault());
calendarBehavior.setWeekOfMonth(newDate.get(weekFields.weekOfMonth()));
setTitle(newDate.getMonth().getValue() + "月");
}
});
代码示例来源:origin: ThreeTen/threetenbp
public int get(TemporalField field) {
if (field instanceof ChronoField) {
return (field.isTimeBased() ? time.get(field) : date.get(field));
代码示例来源:origin: org.threeten/threetenbp
public int get(TemporalField field) {
if (field instanceof ChronoField) {
return (field.isTimeBased() ? time.get(field) : date.get(field));
代码示例来源:origin: ThreeTen/threetenbp
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
if (isSupportedBy(temporal) == false) {
throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
}
int newWby = range().checkValidIntValue(newValue, WEEK_BASED_YEAR); // strict check
LocalDate date = LocalDate.from(temporal);
int dow = date.get(DAY_OF_WEEK);
int week = getWeek(date);
if (week == 53 && getWeekRange(newWby) == 52) {
week = 52;
}
LocalDate resolved = LocalDate.of(newWby, 1, 4); // 4th is guaranteed to be in week one
int days = (dow - resolved.get(DAY_OF_WEEK)) + ((week - 1) * 7);
resolved = resolved.plusDays(days);
return (R) temporal.with(resolved);
}
};
代码示例来源:origin: org.threeten/threetenbp
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
if (isSupportedBy(temporal) == false) {
throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
}
int newWby = range().checkValidIntValue(newValue, WEEK_BASED_YEAR); // strict check
LocalDate date = LocalDate.from(temporal);
int dow = date.get(DAY_OF_WEEK);
int week = getWeek(date);
if (week == 53 && getWeekRange(newWby) == 52) {
week = 52;
}
LocalDate resolved = LocalDate.of(newWby, 1, 4); // 4th is guaranteed to be in week one
int days = (dow - resolved.get(DAY_OF_WEEK)) + ((week - 1) * 7);
resolved = resolved.plusDays(days);
return (R) temporal.with(resolved);
}
};
代码示例来源:origin: ThreeTen/threetenbp
int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
LocalDate date = LocalDate.of(y, moy, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
int dow = DAY_OF_WEEK.checkValidIntValue(fieldValues.remove(DAY_OF_WEEK));
LocalDate date = LocalDate.of(y, moy, 1).plusWeeks(aw - 1).with(nextOrSame(DayOfWeek.of(dow)));
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
LocalDate date = LocalDate.of(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different year");
int dow = DAY_OF_WEEK.checkValidIntValue(fieldValues.remove(DAY_OF_WEEK));
LocalDate date = LocalDate.of(y, 1, 1).plusWeeks(aw - 1).with(nextOrSame(DayOfWeek.of(dow)));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
代码示例来源:origin: org.threeten/threetenbp
int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
LocalDate date = LocalDate.of(y, moy, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
int dow = DAY_OF_WEEK.checkValidIntValue(fieldValues.remove(DAY_OF_WEEK));
LocalDate date = LocalDate.of(y, moy, 1).plusWeeks(aw - 1).with(nextOrSame(DayOfWeek.of(dow)));
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
LocalDate date = LocalDate.of(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different year");
int dow = DAY_OF_WEEK.checkValidIntValue(fieldValues.remove(DAY_OF_WEEK));
LocalDate date = LocalDate.of(y, 1, 1).plusWeeks(aw - 1).with(nextOrSame(DayOfWeek.of(dow)));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
内容来源于网络,如有侵权,请联系作者删除!