当前位置: 首页>>代码示例>>Java>>正文


Java LocalDate.getDayOfWeek方法代码示例

本文整理汇总了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;
}
 
开发者ID:Jibbow,项目名称:FastisFX,代码行数:25,代码来源:DayChooser.java

示例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++;
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:23,代码来源:RangeFilterTests.java

示例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
    }
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:21,代码来源:Main.java

示例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;
}
 
开发者ID:deltadak,项目名称:plep,代码行数:22,代码来源:Controller.java

示例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;
}
 
开发者ID:xabgesagtx,项目名称:mensa-api,代码行数:12,代码来源:WeekdayResultSupplier.java

示例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);
}
 
开发者ID:dev-andremonteiro,项目名称:AlphaLab,代码行数:32,代码来源:FrmSolicitarReservaHorarioPorRequisito.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:IsoFields.java

示例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);
    }
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:11,代码来源:ISOWeeks.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:TCKIsoFields.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:TCKWeekFields.java

示例11: isWeekend

import java.time.LocalDate; //导入方法依赖的package包/类
public boolean isWeekend(LocalDate date) {
    DayOfWeek day = date.getDayOfWeek();
    return day == DayOfWeek.SATURDAY || day == DayOfWeek.SUNDAY;
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:5,代码来源:WorkingDayIndicator.java

示例12: isWeekend

import java.time.LocalDate; //导入方法依赖的package包/类
public static boolean isWeekend(LocalDate date) {
	return date.getDayOfWeek() == DayOfWeek.SATURDAY 
			|| date.getDayOfWeek() == DayOfWeek.SUNDAY;
}
 
开发者ID:vibridi,项目名称:qgu,代码行数:5,代码来源:DateUtils.java

示例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);
        }
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:57,代码来源:MonthSheetViewSkin.java


注:本文中的java.time.LocalDate.getDayOfWeek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。