Example usage for java.time Month of

List of usage examples for java.time Month of

Introduction

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

Prototype

public static Month of(int month) 

Source Link

Document

Obtains an instance of Month from an int value.

Usage

From source file:Main.java

public static void main(String[] args) {
    Month m = Month.of(1);
    System.out.println(m.getValue());
    System.out.println(m.name());
    System.out.println(m.ordinal());
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, Month.AUGUST, 3);
    System.out.println(localDate);
    Month month1 = Month.from(localDate);
    System.out.println(month1);//from w w  w  . j  av  a2 s.com

    Month month2 = Month.of(2);
    System.out.println(month2);

    Month month3 = month2.plus(2);
    System.out.println(month3);

    Month month4 = localDate.getMonth();
    System.out.println(month4);

    int monthIntValue = month2.getValue();
    System.out.println(monthIntValue);
}

From source file:Main.java

/**
 * Returns the current quarter of the given date
 * /* w  ww  .  ja va 2 s . co  m*/
 * @return int (0 .. 3)
 * @param cal
 *          Given date, cannot be null
 */
public static int getQuarter(LocalDate cal) {
    int month = cal.get(ChronoField.MONTH_OF_YEAR);
    switch (Month.of(month)) {
    case JANUARY:
    case FEBRUARY:
    case MARCH:
    default:
        return 0;
    case APRIL:
    case MAY:
    case JUNE:
        return 1;
    case JULY:
    case AUGUST:
    case SEPTEMBER:
        return 2;
    case OCTOBER:
    case NOVEMBER:
    case DECEMBER:
        return 3;
    }
}

From source file:FactFind.PersonalDetails.java

static String CalculateAge(String DOB) {
    LocalDate today = LocalDate.now();

    String[] str_array = DOB.split("/");

    LocalDate birthday = LocalDate.of(Integer.parseInt(str_array[2]), Month.of(Integer.parseInt(str_array[1])),
            Integer.parseInt(str_array[0]));

    Period p = Period.between(birthday, today);

    return Integer.toString(p.getYears());
}

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

@Override
public Map<Month, String> getMonthNames() {
    List<String> months = Arrays.asList(component.getMonthNamesShort());

    return months.stream().collect(Collectors.toMap((String m) -> Month.of(months.indexOf(m) + 1), m -> m));
}