Example usage for java.time LocalDate getDayOfWeek

List of usage examples for java.time LocalDate getDayOfWeek

Introduction

In this page you can find the example usage for java.time LocalDate getDayOfWeek.

Prototype

public DayOfWeek getDayOfWeek() 

Source Link

Document

Gets the day-of-week field, which is an enum DayOfWeek .

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);

    System.out.println(a.getDayOfWeek().name());
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, 2, 15); // 2014-06-15
    DayOfWeek dayOfWeek = date.getDayOfWeek();
    int dayOfWeekIntValue = dayOfWeek.getValue(); // 6
    String dayOfWeekName = dayOfWeek.name(); // SATURDAY

    System.out.println(dayOfWeekIntValue);
    System.out.println(dayOfWeekName);
}

From source file:Main.java

public static void main(String... args) {
    LocalDate independenceDay = LocalDate.of(2014, Month.JULY, 4);
    DayOfWeek dayOfWeek = independenceDay.getDayOfWeek();
    System.out.println(dayOfWeek); // FRIDAY

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, Month.FEBRUARY, 15); // 2014-02-15
    DayOfWeek dayOfWeek = date.getDayOfWeek(); // SATURDAY

    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 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

public static LocalDate[] getWeekday(LocalDate date) {
    int DAYS_OF_WEEK = 7;

    if (date == null) {
        date = LocalDate.now();//from   www . ja  v a2  s  .c o  m
    }

    LocalDate begin = null;
    if (date.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
        begin = date;
    } else {
        begin = date.minusDays(date.getDayOfWeek().getValue());
    }
    LocalDate end = begin.plusDays(DAYS_OF_WEEK - 1);

    LocalDate localDate[] = { begin, end };

    return localDate;

}

From source file:mesclasses.util.NodeUtil.java

public static String getJour(LocalDate date) {

    return Constants.DAYMAP.get(date.getDayOfWeek());
}

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

/**
 * Calculates the number of business days (excluding weekends)
 * between two dates (inclusive)./*w  w  w .j a va  2s  .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:com.github.drbookings.ui.controller.UpcomingController.java

private static String getDateString(final LocalDate date) {
    if (LocalDate.now().equals(date)) {
        return "Today (" + date.toString() + ")";
    } else if (LocalDate.now().plusDays(1).equals(date)) {
        return "Tomorrow (" + date.toString() + ")";
    } else if (LocalDate.now().plusDays(2).equals(date) || LocalDate.now().plusDays(3).equals(date)
            || LocalDate.now().plusDays(4).equals(date)) {
        return "on " + date.getDayOfWeek().toString().charAt(0)
                + date.getDayOfWeek().toString().substring(1).toLowerCase() + " (" + date.toString() + ")";
    } else {/*from   w w w . j  a  va  2s . com*/
        return "on " + date;
    }
}