本文整理匯總了Java中java.time.LocalDate.getDayOfWeek方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.getDayOfWeek方法的具體用法?Java LocalDate.getDayOfWeek怎麽用?Java LocalDate.getDayOfWeek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.getDayOfWeek方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: renderDayItem
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* Creates a node for a given day. Styling should be done via CSS, but
* appropriate CSS classes are assigned to each node.
* @param date A given date the node is associated with.
* @return A node that displays the day of month.
*/
private Node renderDayItem(LocalDate date) {
Label lblDate = new Label(""+date.getDayOfMonth());
lblDate.getStyleClass().add("daychooser-day");
if(date.getDayOfWeek() == DayOfWeek.SATURDAY
|| date.getDayOfWeek() == DayOfWeek.SUNDAY) {
lblDate.getStyleClass().add("daychooser-weekend");
} else {
lblDate.getStyleClass().add("daychooser-weekday");
}
if(date.equals(selectedDateProperty.get())) {
lblDate.getStyleClass().add("daychooser-selected-day");
}
if(date.equals(LocalDate.now())) {
lblDate.getStyleClass().add("daychooser-current-day");
}
return lblDate;
}
示例2: testRangeOfLocalDates
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "LocalDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
final boolean ascend = start.isBefore(end);
final Range<LocalDate> range = Range.of(start, end, step, v -> v.getDayOfWeek() == DayOfWeek.MONDAY);
final Array<LocalDate> array = range.toArray(parallel);
final LocalDate first = array.first(v -> true).map(ArrayValue::getValue).get();
final LocalDate last = array.last(v -> true).map(ArrayValue::getValue).get();
Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
int index = 0;
LocalDate value = first;
while (ascend ? value.isBefore(last) : value.isAfter(last)) {
final LocalDate actual = array.getValue(index);
Assert.assertEquals(actual, value, "Value matches at " + index);
Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
value = ascend ? value.plus(step) : value.minus(step);
while (value.getDayOfWeek() == DayOfWeek.MONDAY) value = ascend ? value.plus(step) : value.minus(step);
index++;
}
}
示例3: localDate
import java.time.LocalDate; //導入方法依賴的package包/類
public static void localDate() {
LocalDate now = LocalDate.now();
LocalDate plus = now.plus(1, ChronoUnit.DAYS);
LocalDate minus = now.minusDays(1);
System.out.println(now); //2017-09-20
System.out.println(plus); //2017-09-21
System.out.println(minus); //2017-09-19
LocalDate customDate = LocalDate.of(2017, Month.SEPTEMBER, 20);
DayOfWeek dayOfWeek = customDate.getDayOfWeek();
System.out.println(dayOfWeek); //WEDNESDAY 星期三
DateTimeFormatter dateTimeFormatter = DateTimeFormatter
.ofLocalizedDate(FormatStyle.MEDIUM)
.withLocale(Locale.CHINA);
LocalDate parse = LocalDate.parse("2017-09-20", dateTimeFormatter);
System.out.println(parse); //2017-09-20
}
示例4: setTitle
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* add title to listview
*
* @param tree
* to use
* @param localDate
* from which to make a title
*
* @return VBox with listview and title
*/
private VBox setTitle(final TreeView<HomeworkTask> tree,
final LocalDate localDate) {
// vbox will contain a title above a list of tasks
VBox vbox = new VBox();
Label title = new Label(localDate.getDayOfWeek() + " " + localDate);
// the pane is used to align both properly (I think)
Pane pane = new Pane();
vbox.getChildren().addAll(title, pane, tree);
VBox.setVgrow(pane, Priority.ALWAYS);
return vbox;
}
示例5: getFittingDateForDayOfWeek
import java.time.LocalDate; //導入方法依賴的package包/類
LocalDate getFittingDateForDayOfWeek(DayOfWeek dayOfWeek, LocalDate date) {
LocalDate result;
DayOfWeek currentDayOfWeek = date.getDayOfWeek();
int diff = dayOfWeek.getValue() - currentDayOfWeek.getValue();
if (diff >= 0) {
result = date.plusDays(diff);
} else {
result = date.plusWeeks(1).plusDays(diff);
}
return result;
}
示例6: dtpData_onAction
import java.time.LocalDate; //導入方法依賴的package包/類
@FXML
void dtpData_onAction(ActionEvent event) {
String diaSemana = new String("column.");
LocalDate data = dtpData.getValue();
switch (data.getDayOfWeek()) {
case MONDAY:
diaSemana += "segunda";
break;
case TUESDAY:
diaSemana += "terca";
break;
case WEDNESDAY:
diaSemana += "quarta";
break;
case THURSDAY:
diaSemana += "quinta";
break;
case FRIDAY:
diaSemana += "sexta";
break;
case SATURDAY:
diaSemana += "sabado";
break;
case SUNDAY:
diaSemana += "domingo";
}
tbcDiaSemana.setText(resources.getString(diaSemana));
List<ReservaEntity> reservas = new ArrayList<ReservaEntity>(reserva.getAtivosNoDia(data));
refreshColunaBotoes(reservas);
}
示例7: getWeekRange
import java.time.LocalDate; //導入方法依賴的package包/類
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;
}
示例8: getWeekRange
import java.time.LocalDate; //導入方法依賴的package包/類
private static DateTimeValueRange getWeekRange(LocalDate date) {
int wby = getWeekBasedYear(date);
date = date.withDayOfYear(1).withYear(wby);
// 53 weeks if standard year starts on Thursday, or Wed in a leap year
if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
return DateTimeValueRange.of(1, 53);
}
return DateTimeValueRange.of(1, 52);
}
示例9: test_loop
import java.time.LocalDate; //導入方法依賴的package包/類
public void test_loop() {
// loop round at least one 400 year cycle, including before 1970
LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960
int year = 1960;
int wby = 1960;
int weekLen = 52;
int week = 1;
while (date.getYear() < 2400) {
DayOfWeek loopDow = date.getDayOfWeek();
if (date.getYear() != year) {
year = date.getYear();
}
if (loopDow == MONDAY) {
week++;
if ((week == 53 && weekLen == 52) || week == 54) {
week = 1;
LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1);
DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek();
weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52);
wby++;
}
}
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek());
date = date.plusDays(1);
}
}
示例10: test_weekOfWeekBasedYearField
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* Verify that the date can be reconstructed from the DOW, WeekOfWeekBasedYear,
* and WeekBasedYear for every combination of start of week
* and minimal days in week.
* @param firstDayOfWeek the first day of the week
* @param minDays the minimum number of days in the week
*/
@Test(dataProvider="weekFields")
public void test_weekOfWeekBasedYearField(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 31); // Known to be ISO Monday
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = weekDef.dayOfWeek();
TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
TemporalField yowbyField = weekDef.weekBasedYear();
for (int i = 1; i <= 15; i++) {
int actualDOW = day.get(dowField);
int actualWOWBY = day.get(wowbyField);
int actualYOWBY = day.get(yowbyField);
// Verify that the combination of day of week and week of month can be used
// to reconstruct the same date.
LocalDate day1 = LocalDate.of(actualYOWBY, 1, 1);
DayOfWeek isoDOW = day1.getDayOfWeek();
int dow = (7 + isoDOW.getValue() - firstDayOfWeek.getValue()) % 7 + 1;
int weekStart = Math.floorMod(1 - dow, 7);
if (weekStart + 1 > weekDef.getMinimalDaysInFirstWeek()) {
// The previous week has the minimum days in the current month to be a 'week'
weekStart -= 7;
}
weekStart += actualDOW - 1;
weekStart += (actualWOWBY - 1) * 7;
LocalDate result = day1.plusDays(weekStart);
assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
+ String.format("%s, ISO Dow: %s, weekStart: %s, actualDOW: %s, actualWOWBY: %s, YearOfWBY: %d, expected day: %s, result: %s%n",
weekDef, day.getDayOfWeek(), weekStart, actualDOW, actualWOWBY, actualYOWBY, day, result));
day = day.plusDays(1);
}
}
示例11: isWeekend
import java.time.LocalDate; //導入方法依賴的package包/類
public boolean isWeekend(LocalDate date) {
DayOfWeek day = date.getDayOfWeek();
return day == DayOfWeek.SATURDAY || day == DayOfWeek.SUNDAY;
}
示例12: isWeekend
import java.time.LocalDate; //導入方法依賴的package包/類
public static boolean isWeekend(LocalDate date) {
return date.getDayOfWeek() == DayOfWeek.SATURDAY
|| date.getDayOfWeek() == DayOfWeek.SUNDAY;
}
示例13: buildCells
import java.time.LocalDate; //導入方法依賴的package包/類
private void buildCells(YearMonth yearMonth, int colIndex) {
List<Node> cells = new ArrayList<>();
Node header = buildHeaderCell(yearMonth);
header.getStyleClass().add("month-header");
cells.add(header);
LocalDate start = yearMonth.atDay(1);
LocalDate end = yearMonth.atEndOfMonth();
if (getSkinnable().getWeekDayLayout() == WeekDayLayoutStrategy.ALIGNED) {
DayOfWeek firstDayOfWeek = getSkinnable().getFirstDayOfWeek();
DayOfWeek startDayOfWeek = start.getDayOfWeek();
int distanceDays = Math.abs(firstDayOfWeek.getValue() - startDayOfWeek.getValue());
while (distanceDays-- > 0) {
cells.add(buildCell(null));
}
}
while (start.isBefore(end) || start.isEqual(end)) {
cells.add(buildCell(start));
start = start.plusDays(1);
}
buildEmptyCellBottom(cells);
final YearMonth extendedStart = getSkinnable().getExtendedStartMonth();
final YearMonth extendedEnd = getSkinnable().getExtendedEndMonth();
cells.forEach(cell -> {
if (extendedStart.equals(yearMonth)) {
cell.getStyleClass().add("first-month");
} else if (extendedEnd.equals(yearMonth)) {
cell.getStyleClass().add("last-month");
} else {
cell.getStyleClass().add("middle-month");
}
});
for (int i = 0; i < cells.size(); i++) {
Node node = cells.get(i);
grid.add(node, colIndex, i + 1);
if (node instanceof DateCell) {
final Position position = new Position(colIndex, i);
final DateCell dateCell = (DateCell) node;
final LocalDate date = dateCell.getDate();
cellMap.put(date, dateCell);
positionToDateCellMap.put(position, dateCell);
dateToPositionMap.put(date, position);
}
}
}