Example usage for java.time DayOfWeek of

List of usage examples for java.time DayOfWeek of

Introduction

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

Prototype

public static DayOfWeek of(int dayOfWeek) 

Source Link

Document

Obtains an instance of DayOfWeek from an int value.

Usage

From source file:Main.java

public static void main(String[] args) {
    DayOfWeek dayOfWeek = DayOfWeek.of(1);
    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 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: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

/**
 * This method checks whether the given date object is representing a date at
 * the weekend (Saturday or Sunday)/*  ww  w . jav  a  2s.  c  o m*/
 * 
 * @param date
 *          Date to check, cannot be null
 * @return TRUE is Saturday or Sunday
 */
public static boolean isWeekend(LocalDate date) {
    DayOfWeek dayOfWeek = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK));
    switch (dayOfWeek) {
    case SATURDAY:
    case SUNDAY:
        return true;
    default:
        return false;
    }
}

From source file:Main.java

/**
 * The methods calculates the previous working day. It only recognize Saturday
 * and Sunday as non -working days.// www. j  a v  a  2s . c o m
 * 
 * @param date
 *          Date as starting point for the calculation, cannot be null
 * @return The previous working day
 */
public static LocalDate getPreviousWorkingDay(LocalDate date) {
    DayOfWeek dayOfWeek = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK));
    switch (dayOfWeek) {
    case MONDAY:
        return date.minus(3, ChronoUnit.DAYS);
    case SUNDAY:
        return date.minus(2, ChronoUnit.DAYS);
    default:
        return date.minus(1, ChronoUnit.DAYS);

    }
}

From source file:Main.java

public static Boolean queryFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(ChronoField.DAY_OF_MONTH) && temporal.isSupported(ChronoField.DAY_OF_WEEK)) {
        int dayOfMonth = temporal.get(ChronoField.DAY_OF_MONTH);
        int weekDay = temporal.get(ChronoField.DAY_OF_WEEK);
        DayOfWeek dayOfWeek = DayOfWeek.of(weekDay);
        if (dayOfMonth == 1 && dayOfWeek == DayOfWeek.MONDAY) {
            return Boolean.TRUE;
        }/*w  ww  .j ava  2  s  .  co m*/
    }
    return Boolean.FALSE;
}

From source file:Main.java

@Override
public Boolean queryFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(ChronoField.DAY_OF_MONTH) && temporal.isSupported(ChronoField.DAY_OF_WEEK)) {
        int dayOfMonth = temporal.get(ChronoField.DAY_OF_MONTH);
        int weekDay = temporal.get(ChronoField.DAY_OF_WEEK);
        DayOfWeek dayOfWeek = DayOfWeek.of(weekDay);
        if (dayOfMonth == 1 && dayOfWeek == DayOfWeek.MONDAY) {
            return Boolean.TRUE;
        }/*w  w w.j a  v a2 s  .co  m*/
    }
    return Boolean.FALSE;
}

From source file:com.haulmont.cuba.web.gui.components.WebCalendar.java

@Override
public Map<DayOfWeek, String> getDayNames() {
    List<String> days = Arrays.asList(component.getDayNamesShort().clone());

    int shift = Math.abs(component.getFirstDayOfWeek() - java.util.Calendar.MONDAY) + 1;
    Collections.rotate(days, -shift);

    return days.stream().collect(Collectors.toMap((String d) -> DayOfWeek.of(days.indexOf(d) + 1), d -> d));
}