Example usage for java.time LocalDate getMonth

List of usage examples for java.time LocalDate getMonth

Introduction

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

Prototype

public Month getMonth() 

Source Link

Document

Gets the month-of-year field using the Month enum.

Usage

From source file:Main.java

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

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

From source file:Main.java

public static void main(String[] argv) {
    LocalDate dateOfBirth = LocalDate.now();
    MonthDay birthday = MonthDay.of(dateOfBirth.getMonth(), dateOfBirth.getDayOfMonth());
    MonthDay currentMonthDay = MonthDay.from(LocalDate.now());

    if (currentMonthDay.equals(birthday)) {
        System.out.println("Yes!!");
    } else {/*from w  w w  .j  a  v a2 s .com*/
        System.out.println("Sorry, today is not your birthday");
    }
}

From source file:Main.java

public static void main(String[] argv) {

    LocalDate date1 = LocalDate.now();
    LocalDate date2 = LocalDate.of(date1.getYear(), date1.getMonth(), date1.getDayOfMonth());
    if (date1.equals(date2)) {
        System.out.printf("Today %s and date1 %s are same date %n", date1, date2);
    }//from  ww w.j av  a  2s . c om

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, 2, 15); // 2014-02-15
    Month february = date.getMonth();
    System.out.println(february); // FEBRUARY

    int februaryIntValue = february.getValue();
    System.out.println(februaryIntValue); // 2

    // 28 , 29/*w  ww .ja v a2  s  . c o m*/
    System.out.println(String.format("%s , %s", february.minLength(), february.maxLength()));

    Month firstMonthOfQuarter = february.firstMonthOfQuarter();
    System.out.println(firstMonthOfQuarter); // JANUARY
}

From source file:Main.java

public static void main(String[] args) {
    Month month = Month.valueOf("March".toUpperCase());

    System.out.printf("For the month of %s:%n", month);
    LocalDate date = Year.now().atMonth(month).atDay(1).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
    Month mi = date.getMonth();
    while (mi == month) {
        System.out.printf("%s%n", date);
        date = date.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
        mi = date.getMonth();/*from  www  .ja v a  2  s  .  co m*/
    }
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, 6, 21);
    int year = localDate.getYear();
    System.out.println(year);//from ww  w.  j  a  v a 2  s  . c  om
    Month month = localDate.getMonth();
    System.out.println(month);

    int day = localDate.getDayOfMonth();
    System.out.println(day);

}

From source file:ListMondays.java

public static void main(String[] args) {
    Month month = null;//from w ww.  j  a  v  a  2  s  .c  o m

    if (args.length < 1) {
        System.out.printf("Usage: ListMondays <month>%n");
        throw new IllegalArgumentException();
    }

    try {
        month = Month.valueOf(args[0].toUpperCase());
    } catch (IllegalArgumentException exc) {
        System.out.printf("%s is not a valid month.%n", args[0]);
        throw exc; // Rethrow the exception.
    }

    System.out.printf("For the month of %s:%n", month);
    LocalDate date = Year.now().atMonth(month).atDay(1).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
    Month mi = date.getMonth();
    while (mi == month) {
        System.out.printf("%s%n", date);
        date = date.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
        mi = date.getMonth();
    }
}

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 ww .  ja v  a 2s . co m*/

    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

public static String getMonthName(Integer month) {
    LocalDate localDate = LocalDate.of(0, month, 0);
    return localDate.getMonth().name();
}

From source file:Main.java

public static String getMonthName(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from w  w w. j  av  a 2  s . c  o m
    LocalDate localDate = LocalDate.of(0, cal.get(Calendar.MONTH) + 1, 1);
    return localDate.getMonth().name();
}