当前位置: 首页>>代码示例>>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;未经允许,请勿转载。