當前位置: 首頁>>代碼示例>>Java>>正文


Java DayOfWeek.getValue方法代碼示例

本文整理匯總了Java中java.time.DayOfWeek.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java DayOfWeek.getValue方法的具體用法?Java DayOfWeek.getValue怎麽用?Java DayOfWeek.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.DayOfWeek的用法示例。


在下文中一共展示了DayOfWeek.getValue方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFittingDateForDayOfWeek

import java.time.DayOfWeek; //導入方法依賴的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

示例2: test_weekOfWeekBasedYearField

import java.time.DayOfWeek; //導入方法依賴的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

示例3: isNeededToLaunch

import java.time.DayOfWeek; //導入方法依賴的package包/類
/**
 * Vérifie si le batch doit être lancé grace a son schedul
 * 
 * @param batch
 * @param lastExec
 * @return true si le batch doit etre lance ou non
 */
private Boolean isNeededToLaunch(Batch batch, LocalDateTime lastExec) {
	/* Vérification si le batch doit etre lancé immediatement */
	if (batch.getTemIsLaunchImediaBatch()) {
		batch.setTemIsLaunchImediaBatch(false);
		batchRepository.saveAndFlush(batch);
		return true;
	}
	LocalDateTime now = LocalDateTime.now();

	/* Vérification si le batch doit etre lancé à une date précise */
	if (batch.getFixeYearBatch() != null && batch.getFixeMonthBatch() != null && batch.getFixeDayBatch() != null) {
		if (now.getYear() != batch.getFixeYearBatch() || now.getMonth().getValue() != batch.getFixeMonthBatch()
				|| now.getDayOfMonth() != batch.getFixeDayBatch()) {
			return false;
		}
	}
	/*
	 * Vérification si le batch doit etre lancé annuelement avec un mois donné et un
	 * jour donné
	 */
	if (batch.getFixeMonthBatch() != null && batch.getFixeDayBatch() != null) {
		if (now.getMonth().getValue() != batch.getFixeMonthBatch()
				|| now.getDayOfMonth() != batch.getFixeDayBatch()) {
			return false;
		}
	}
	/* Vérification si le batch doit etre lancé mensuelement avec un jour donné */
	else if (batch.getFixeDayBatch() != null) {
		if (now.getDayOfMonth() != batch.getFixeDayBatch()) {
			return false;
		}
	}

	/*
	 * Sinon vérification si le batch doit etre lancé hebdo avec les journs précisés
	 */
	else {
		DayOfWeek today = now.getDayOfWeek();
		if (!batch.getTemLundiBatch() && today.getValue() == 1) {
			return false;
		} else if (!batch.getTemMardiBatch() && today.getValue() == 2) {
			return false;
		} else if (!batch.getTemMercrBatch() && today.getValue() == 3) {
			return false;
		} else if (!batch.getTemJeudiBatch() && today.getValue() == 4) {
			return false;
		} else if (!batch.getTemVendrediBatch() && today.getValue() == 5) {
			return false;
		} else if (!batch.getTemSamediBatch() && today.getValue() == 6) {
			return false;
		} else if (!batch.getTemDimanBatch() && today.getValue() == 7) {
			return false;
		}
	}

	logger.trace("OK à lancer aujourd'hui");
	if ((batch.getFixeHourBatch().isAfter(lastExec.toLocalTime()))
			&& batch.getFixeHourBatch().isBefore(now.toLocalTime())) {
		logger.trace("OK à lancer maintenant");
		return true;
	}
	return false;
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:71,代碼來源:BatchController.java

示例4: DayOfWeekInMonth

import java.time.DayOfWeek; //導入方法依賴的package包/類
private DayOfWeekInMonth(int ordinal, DayOfWeek dow) {

      super();
      this.ordinal = ordinal;
      this.dowValue = dow.getValue();
    }
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:7,代碼來源:DateTimeAdjusters.java

示例5: RelativeDayOfWeek

import java.time.DayOfWeek; //導入方法依賴的package包/類
private RelativeDayOfWeek(int relative, DayOfWeek dayOfWeek) {

      Jdk7Methods.Objects_requireNonNull(dayOfWeek, "dayOfWeek");
      this.relative = relative;
      this.dowValue = dayOfWeek.getValue();
    }
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:7,代碼來源:DateTimeAdjusters.java

示例6: testDateTimeInfo

import java.time.DayOfWeek; //導入方法依賴的package包/類
/**
 * 獲取時間節點的詳細信息
 */
@Test
public void testDateTimeInfo(){
    LocalDateTime ldt = LocalDateTime.now();

    // 獲取當前的年份
    int year = ldt.getYear();
    System.out.println(year);

    // 當前年中的第幾天
    int dayOfYear = ldt.getDayOfYear();
    System.out.println(dayOfYear);

    // 當前月份中的第幾天
    int dayOfMonth = ldt.getDayOfMonth();
    System.out.println(dayOfMonth);

    // 當前周中的第幾天
    DayOfWeek dayOfWeek = ldt.getDayOfWeek();
    int dayOfWeekValue = dayOfWeek.getValue();
    System.out.println(dayOfWeekValue);

    // 獲取小時
    int hour = ldt.getHour();
    System.out.println(hour);

    // 獲取月份信息
    Month month = ldt.getMonth();
    int monthValue = month.getValue();
    System.out.println(monthValue);
    int ldtMonthValue = ldt.getMonthValue();
    System.out.println(ldtMonthValue);

    // 獲取分鍾
    int minute = ldt.getMinute();
    System.out.println(minute);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:40,代碼來源:LocalDateTimeDemo.java

示例7: next

import java.time.DayOfWeek; //導入方法依賴的package包/類
/**
 * Returns the next day-of-week adjuster, which adjusts the date to the
 * first occurrence of the specified day-of-week after the date being adjusted.
 * <p>
 * The ISO calendar system behaves as follows:<br>
 * The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-17 (two days later).<br>
 * The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-19 (four days later).<br>
 * The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-22 (seven days later).
 * <p>
 * The behavior is suitable for use with most calendar systems.
 * It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
 * and assumes a seven day week.
 *
 * @param dayOfWeek  the day-of-week to move the date to, not null
 * @return the next day-of-week adjuster, not null
 */
public static TemporalAdjuster next(DayOfWeek dayOfWeek) {
    int dowValue = dayOfWeek.getValue();
    return (temporal) -> {
        int calDow = temporal.get(DAY_OF_WEEK);
        int daysDiff = calDow - dowValue;
        return temporal.plus(daysDiff >= 0 ? 7 - daysDiff : -daysDiff, DAYS);
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:TemporalAdjusters.java

示例8: nextOrSame

import java.time.DayOfWeek; //導入方法依賴的package包/類
/**
 * Returns the next-or-same day-of-week adjuster, which adjusts the date to the
 * first occurrence of the specified day-of-week after the date being adjusted
 * unless it is already on that day in which case the same object is returned.
 * <p>
 * The ISO calendar system behaves as follows:<br>
 * The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-17 (two days later).<br>
 * The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-19 (four days later).<br>
 * The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-15 (same as input).
 * <p>
 * The behavior is suitable for use with most calendar systems.
 * It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
 * and assumes a seven day week.
 *
 * @param dayOfWeek  the day-of-week to check for or move the date to, not null
 * @return the next-or-same day-of-week adjuster, not null
 */
public static TemporalAdjuster nextOrSame(DayOfWeek dayOfWeek) {
    int dowValue = dayOfWeek.getValue();
    return (temporal) -> {
        int calDow = temporal.get(DAY_OF_WEEK);
        if (calDow == dowValue) {
            return temporal;
        }
        int daysDiff = calDow - dowValue;
        return temporal.plus(daysDiff >= 0 ? 7 - daysDiff : -daysDiff, DAYS);
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:TemporalAdjusters.java

示例9: previous

import java.time.DayOfWeek; //導入方法依賴的package包/類
/**
 * Returns the previous day-of-week adjuster, which adjusts the date to the
 * first occurrence of the specified day-of-week before the date being adjusted.
 * <p>
 * The ISO calendar system behaves as follows:<br>
 * The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-10 (five days earlier).<br>
 * The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-12 (three days earlier).<br>
 * The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-08 (seven days earlier).
 * <p>
 * The behavior is suitable for use with most calendar systems.
 * It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
 * and assumes a seven day week.
 *
 * @param dayOfWeek  the day-of-week to move the date to, not null
 * @return the previous day-of-week adjuster, not null
 */
public static TemporalAdjuster previous(DayOfWeek dayOfWeek) {
    int dowValue = dayOfWeek.getValue();
    return (temporal) -> {
        int calDow = temporal.get(DAY_OF_WEEK);
        int daysDiff = dowValue - calDow;
        return temporal.minus(daysDiff >= 0 ? 7 - daysDiff : -daysDiff, DAYS);
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:TemporalAdjusters.java

示例10: previousOrSame

import java.time.DayOfWeek; //導入方法依賴的package包/類
/**
 * Returns the previous-or-same day-of-week adjuster, which adjusts the date to the
 * first occurrence of the specified day-of-week before the date being adjusted
 * unless it is already on that day in which case the same object is returned.
 * <p>
 * The ISO calendar system behaves as follows:<br>
 * The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-10 (five days earlier).<br>
 * The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-12 (three days earlier).<br>
 * The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-15 (same as input).
 * <p>
 * The behavior is suitable for use with most calendar systems.
 * It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
 * and assumes a seven day week.
 *
 * @param dayOfWeek  the day-of-week to check for or move the date to, not null
 * @return the previous-or-same day-of-week adjuster, not null
 */
public static TemporalAdjuster previousOrSame(DayOfWeek dayOfWeek) {
    int dowValue = dayOfWeek.getValue();
    return (temporal) -> {
        int calDow = temporal.get(DAY_OF_WEEK);
        if (calDow == dowValue) {
            return temporal;
        }
        int daysDiff = dowValue - calDow;
        return temporal.minus(daysDiff >= 0 ? 7 - daysDiff : -daysDiff, DAYS);
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:TemporalAdjusters.java


注:本文中的java.time.DayOfWeek.getValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。