Example usage for java.time DayOfWeek getValue

List of usage examples for java.time DayOfWeek getValue

Introduction

In this page you can find the example usage for java.time DayOfWeek getValue.

Prototype

public int getValue() 

Source Link

Document

Gets the day-of-week int value.

Usage

From source file:Main.java

public static void main(String[] args) {
    DayOfWeek dayOfWeek = DayOfWeek.valueOf("MONDAY");
    System.out.println(dayOfWeek.name());
    System.out.println(dayOfWeek.getValue());
    System.out.println(dayOfWeek.ordinal());
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, Month.JUNE, 21);
    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);
    System.out.println(dayOfWeek.name());
    System.out.println(dayOfWeek.getValue());
    System.out.println(dayOfWeek.ordinal());
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, 6, 21);
    System.out.println(localDate);
    DayOfWeek dayOfWeek1 = DayOfWeek.from(localDate);
    System.out.println(dayOfWeek1);
    int intValue = dayOfWeek1.getValue();
    System.out.println(intValue);
    DayOfWeek dayOfWeek2 = localDate.getDayOfWeek();
    System.out.println(dayOfWeek2);
    DayOfWeek dayOfWeekFromInteger = DayOfWeek.of(7);
    System.out.println(dayOfWeekFromInteger);
    DayOfWeek dayOfWeekAdded = dayOfWeekFromInteger.plus(1);
    System.out.println(dayOfWeekAdded);
    DayOfWeek dayOfWeekSubtracted = dayOfWeekFromInteger.minus(2);
    System.out.println(dayOfWeekSubtracted);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, 2, 15); // 2014-02-15
    // ISO-8601 standard
    // the day-of-week to represent, from 1 (Monday) to 7 (Sunday)
    DayOfWeek dayOfWeek = date.getDayOfWeek();
    System.out.println(dayOfWeek); // SATURDAY

    System.out.println(DayOfWeek.of(3)); // WEDNESDAY

    System.out.println(dayOfWeek.getValue()); // 6
    System.out.println(dayOfWeek.name()); // SATURDAY

    System.out.println(date.getDayOfMonth()); // 15
    System.out.println(date.atStartOfDay()); // 2014-02-15 00:00

    System.out.println("DayOfWeek");
    dayOfWeek = DayOfWeek.FRIDAY;
    Locale locale = Locale.getDefault();
    System.out.println(dayOfWeek.getDisplayName(TextStyle.FULL, locale)); // Friday
    System.out.println(dayOfWeek.getDisplayName(TextStyle.NARROW, locale)); // F
    System.out.println(dayOfWeek.getDisplayName(TextStyle.SHORT, locale)); // Fri
}

From source file:com.nridge.core.base.std.DatUtl.java

/**
 * Calculates the number of business days (excluding weekends)
 * between two dates (inclusive)./*from  w w  w.j  a  va2s.  c  o m*/
 * <p>
 * https://stackoverflow.com/questions/4600034/calculate-number-of-weekdays-between-two-dates-in-java
 * </p>
 * @param aStartDate Start date.
 * @param anEndDate End date.
 *
 * @return Number of business days.
 */
@SuppressWarnings("UnnecessaryLocalVariable")
public static long calculateBusinessDays(LocalDate aStartDate, LocalDate anEndDate) {
    DayOfWeek startWeekDay = aStartDate.getDayOfWeek().getValue() < 6 ? aStartDate.getDayOfWeek()
            : DayOfWeek.MONDAY;
    DayOfWeek endWeekDay = anEndDate.getDayOfWeek().getValue() < 6 ? anEndDate.getDayOfWeek()
            : DayOfWeek.FRIDAY;

    long numberOfWeeks = ChronoUnit.DAYS.between(aStartDate, anEndDate) / 7;
    long totalWeekDays = numberOfWeeks * 5 + Math.floorMod(endWeekDay.getValue() - startWeekDay.getValue(), 5);

    return totalWeekDays + 1;
}

From source file:io.stallion.jobs.Schedule.java

/**
 * Set the days of the week on which the task is to run.
 *
 * @param days/*from w ww .  jav a2  s .c o  m*/
 * @return
 */
public Schedule daysOfWeek(DayOfWeek... days) {
    this._days.verifyAndUpdateUnset();
    this._days.setIntervalType(Days.IntervalType.DAY_OF_WEEK);
    for (DayOfWeek day : days) {
        this._days.add(day.getValue());
    }
    return this;
}

From source file:io.stallion.jobs.Schedule.java

/**
 * Runs the given days of the week, every other week.
 *
 * @param startingAt/*from w ww . j  a  v a 2s  .  c  om*/
 * @param days
 * @return
 */
public Schedule daysBiweekly(Long startingAt, DayOfWeek... days) {
    this._days.verifyAndUpdateUnset();
    this._days.setIntervalType(Days.IntervalType.BIWEEKLY_DAY_OF_WEEK);
    for (DayOfWeek day : days) {
        this._days.add(day.getValue());
    }
    ZonedDateTime startingWeek = ZonedDateTime.ofInstant(Instant.ofEpochMilli(startingAt), ZoneId.of("UTC"));
    // Get the Monday 12PM of that week
    startingWeek = startingWeek.minusDays(startingWeek.getDayOfWeek().getValue() - 1).withSecond(0).withHour(12)
            .withMinute(0).withNano(0);
    this._days.setStartingDate(startingWeek);
    return this;
}