本文整理了Java中org.threeten.bp.LocalDate.getDayOfWeek()
方法的一些代码示例,展示了LocalDate.getDayOfWeek()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.getDayOfWeek()
方法的具体详情如下:
包路径:org.threeten.bp.LocalDate
类名称:LocalDate
方法名:getDayOfWeek
[英]Gets the day-of-week field, which is an enum DayOfWeek.
This method returns the enum DayOfWeek for the day-of-week. This avoids confusion as to what int values mean. If you need access to the primitive int value then the enum provides the DayOfWeek#getValue().
Additional information can be obtained from the DayOfWeek. This includes textual names of the values.
[中]获取星期天字段,该字段是枚举DayOfWeek。
此方法返回星期几的枚举DayOfWeek。这避免了对int值的含义的混淆。如果需要访问原语int值,则枚举提供DayOfWeek#getValue()。
更多信息可从DayOfWeek获得。这包括值的文本名称。
代码示例来源:origin: prolificinteractive/material-calendarview
@Override public boolean shouldDecorate(final CalendarDay day) {
final DayOfWeek weekDay = day.getDate().getDayOfWeek();
return weekDay == DayOfWeek.SATURDAY || weekDay == DayOfWeek.SUNDAY;
}
代码示例来源:origin: prolificinteractive/material-calendarview
public StateBuilder() {
calendarMode = CalendarMode.MONTHS;
firstDayOfWeek =
LocalDate.now().with(WeekFields.of(Locale.getDefault()).dayOfWeek(), 1).getDayOfWeek();
}
代码示例来源:origin: prolificinteractive/material-calendarview
private void buildWeekDays(LocalDate calendar) {
LocalDate local = calendar;
for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
WeekDayView weekDayView = new WeekDayView(getContext(), local.getDayOfWeek());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
weekDayView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
}
weekDayViews.add(weekDayView);
addView(weekDayView);
local = local.plusDays(1);
}
}
代码示例来源:origin: prolificinteractive/material-calendarview
protected LocalDate resetAndGetWorkingCalendar() {
final TemporalField firstDayOfWeek = WeekFields.of(this.firstDayOfWeek, 1).dayOfWeek();
final LocalDate temp = getFirstViewDay().getDate().with(firstDayOfWeek, 1);
int dow = temp.getDayOfWeek().getValue();
int delta = getFirstDayOfWeek().getValue() - dow;
//If the delta is positive, we want to remove a week
boolean removeRow = showOtherMonths(showOtherDates) ? delta >= 0 : delta > 0;
if (removeRow) {
delta -= DEFAULT_DAYS_IN_WEEK;
}
return temp.plusDays(delta);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Gets the day-of-week field, which is an enum {@code DayOfWeek}.
* <p>
* This method returns the enum {@link DayOfWeek} for the day-of-week.
* This avoids confusion as to what {@code int} values mean.
* If you need access to the primitive {@code int} value then the enum
* provides the {@link DayOfWeek#getValue() int value}.
* <p>
* Additional information can be obtained from the {@code DayOfWeek}.
* This includes textual names of the values.
*
* @return the day-of-week, not null
*/
public DayOfWeek getDayOfWeek() {
return date.getDayOfWeek();
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Gets the day-of-week field, which is an enum {@code DayOfWeek}.
* <p>
* This method returns the enum {@link DayOfWeek} for the day-of-week.
* This avoids confusion as to what {@code int} values mean.
* If you need access to the primitive {@code int} value then the enum
* provides the {@link DayOfWeek#getValue() int value}.
* <p>
* Additional information can be obtained from the {@code DayOfWeek}.
* This includes textual names of the values.
*
* @return the day-of-week, not null
*/
public DayOfWeek getDayOfWeek() {
return date.getDayOfWeek();
}
代码示例来源:origin: ThreeTen/threetenbp
private static int getWeekRange(int wby) {
LocalDate date = LocalDate.of(wby, 1, 1);
// 53 weeks if standard year starts on Thursday, or Wed in a leap year
if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
return 53;
}
return 52;
}
代码示例来源:origin: org.threeten/threetenbp
private static int getWeekRange(int wby) {
LocalDate date = LocalDate.of(wby, 1, 1);
// 53 weeks if standard year starts on Thursday, or Wed in a leap year
if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
return 53;
}
return 52;
}
代码示例来源:origin: org.threeten/threetenbp
private static int getWeekBasedYear(LocalDate date) {
int year = date.getYear();
int doy = date.getDayOfYear();
if (doy <= 3) {
int dow = date.getDayOfWeek().ordinal();
if (doy - dow < -2) {
year--;
}
} else if (doy >= 363) {
int dow = date.getDayOfWeek().ordinal();
doy = doy - 363 - (date.isLeapYear() ? 1 : 0);
if (doy - dow >= 0) {
year++;
}
}
return year;
}
}
代码示例来源:origin: ThreeTen/threetenbp
private static int getWeekBasedYear(LocalDate date) {
int year = date.getYear();
int doy = date.getDayOfYear();
if (doy <= 3) {
int dow = date.getDayOfWeek().ordinal();
if (doy - dow < -2) {
year--;
}
} else if (doy >= 363) {
int dow = date.getDayOfWeek().ordinal();
doy = doy - 363 - (date.isLeapYear() ? 1 : 0);
if (doy - dow >= 0) {
year++;
}
}
return year;
}
}
代码示例来源: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: shrikanth7698/Collapsible-Calendar-View-Android
DayOfWeek firstDayOfWeek = mCal.getDayOfWeek();
代码示例来源:origin: org.threeten/threetenbp
private int get0(TemporalField field) {
switch ((ChronoField) field) {
case DAY_OF_WEEK: return getDayOfWeek().getValue();
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1;
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
case DAY_OF_MONTH: return day;
case DAY_OF_YEAR: return getDayOfYear();
case EPOCH_DAY: throw new DateTimeException("Field too large for an int: " + field);
case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1;
case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
case MONTH_OF_YEAR: return month;
case PROLEPTIC_MONTH: throw new DateTimeException("Field too large for an int: " + field);
case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year);
case YEAR: return year;
case ERA: return (year >= 1 ? 1 : 0);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
代码示例来源:origin: ThreeTen/threetenbp
private int get0(TemporalField field) {
switch ((ChronoField) field) {
case DAY_OF_WEEK: return getDayOfWeek().getValue();
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1;
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
case DAY_OF_MONTH: return day;
case DAY_OF_YEAR: return getDayOfYear();
case EPOCH_DAY: throw new DateTimeException("Field too large for an int: " + field);
case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1;
case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
case MONTH_OF_YEAR: return month;
case PROLEPTIC_MONTH: throw new DateTimeException("Field too large for an int: " + field);
case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year);
case YEAR: return year;
case ERA: return (year >= 1 ? 1 : 0);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
代码示例来源:origin: ThreeTen/threetenbp
private static int getWeek(LocalDate date) {
int dow0 = date.getDayOfWeek().ordinal();
int doy0 = date.getDayOfYear() - 1;
int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero)
int alignedWeek = doyThu0 / 7;
int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
int firstMonDoy0 = firstThuDoy0 - 3;
if (firstMonDoy0 < -3) {
firstMonDoy0 += 7;
}
if (doy0 < firstMonDoy0) {
return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
}
int week = ((doy0 - firstMonDoy0) / 7) + 1;
if (week == 53) {
if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
week = 1;
}
}
return week;
}
代码示例来源:origin: org.threeten/threetenbp
private static int getWeek(LocalDate date) {
int dow0 = date.getDayOfWeek().ordinal();
int doy0 = date.getDayOfYear() - 1;
int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero)
int alignedWeek = doyThu0 / 7;
int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
int firstMonDoy0 = firstThuDoy0 - 3;
if (firstMonDoy0 < -3) {
firstMonDoy0 += 7;
}
if (doy0 < firstMonDoy0) {
return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
}
int week = ((doy0 - firstMonDoy0) / 7) + 1;
if (week == 53) {
if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
week = 1;
}
}
return week;
}
代码示例来源: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: org.threeten/threetenbp
f.checkValidValue(newValue);
switch (f) {
case DAY_OF_WEEK: return plusDays(newValue - getDayOfWeek().getValue());
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
代码示例来源:origin: ThreeTen/threetenbp
f.checkValidValue(newValue);
switch (f) {
case DAY_OF_WEEK: return plusDays(newValue - getDayOfWeek().getValue());
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
内容来源于网络,如有侵权,请联系作者删除!