Example usage for java.time LocalDate of

List of usage examples for java.time LocalDate of

Introduction

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

Prototype

public static LocalDate of(int year, int month, int dayOfMonth) 

Source Link

Document

Obtains an instance of LocalDate from a year, month and day.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate ld1 = LocalDate.of(2013, 12, 1);
    Boolean is = ld1.query(new Monday1Query());
    System.out.println(is);/*from ww w .j ava  2 s .  c o  m*/

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2012, 11, 23);
    System.out.println(localDate.plus(3, ChronoUnit.DAYS)); //2012-11-26

    System.out.println(localDate.plus(Period.ofDays(3))); //2012-11-26
    try {/*from w  w w . jav  a  2  s . c o m*/
        System.out.println(localDate.plus(Duration.ofDays(3)));

        System.out.println(localDate.plus(4, ChronoUnit.FOREVER));
    } catch (UnsupportedTemporalTypeException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate july_2014 = LocalDate.of(2014, 7, 20);
    LocalDate nextPayday = july_2014.with(new FirstTuesdayAdjuster());
    System.out.println(nextPayday);
    LocalDate august_2009 = LocalDate.of(2009, 8, 20);
    nextPayday = august_2009.with(new FirstTuesdayAdjuster());
    System.out.println(nextPayday);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, Month.JUNE, 21);
    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);

    TemporalQuery<TemporalUnit> localDateQuery = TemporalQueries.precision();

    System.out.println(dayOfWeek.query(localDateQuery));
}

From source file:Main.java

public static void main(String[] args) {
    // the current date
    LocalDate currentDate = LocalDate.now();
    System.out.println(currentDate);

    // 2014-02-10
    LocalDate tenthFeb2014 = LocalDate.of(2014, Month.FEBRUARY, 10);
    System.out.println(tenthFeb2014); // 2014-02-10

    // months values start at 1 (2014-08-01)
    LocalDate firstAug2014 = LocalDate.of(2014, 8, 1);
    System.out.println(firstAug2014); // 2014-08-01

    // the 65th day of 2010 (2010-03-06)
    LocalDate sixtyFifthDayOf2010 = LocalDate.ofYearDay(2010, 65);
    System.out.println(sixtyFifthDayOf2010); // 2014-03-06
}

From source file:Main.java

public static void main(String[] args) {
    // Get the current local date
    LocalDate localDate1 = LocalDate.now();
    System.out.println(localDate1);
    // Create a  local date
    LocalDate localDate2 = LocalDate.of(2014, Month.JUNE, 21);
    System.out.println(localDate2);
    // 10000  days after the epoch date 1970-01-01
    LocalDate localDate3 = LocalDate.ofEpochDay(10000);
    System.out.println(localDate3);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate ld = LocalDate.of(2014, Month.JUNE, 21);
    LocalTime lt = LocalTime.of(17, 30, 20);
    LocalDateTime ldt = LocalDateTime.of(ld, lt);

    DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
    System.out.println("Formatter  Default Locale: " + fmt.getLocale());
    System.out.println("Short  Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
    System.out.println("Medium Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    System.out.println("Long  Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
    System.out.println("Full  Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
    System.out.println("Short Time:  " + fmt.format(lt));

    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
    System.out.println("Short  Datetime: " + fmt.format(ldt));

    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
    System.out.println("Medium Datetime: " + fmt.format(ldt));

    // Use German locale to format the datetime in medius style
    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.GERMAN);
    System.out.println(fmt.format(ldt));

    // Use Indian(English) locale to format datetime in short style
    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(new Locale("en", "IN"));
    System.out.println(fmt.format(ldt));

    // Use Indian(English) locale to format datetime in medium style
    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(new Locale("en", "IN"));
    System.out.println(fmt.format(ldt));

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate today = LocalDate.now();

    // Get the Year, check if it's leap year
    System.out.println("Year " + today.getYear() + " is Leap Year? " + today.isLeapYear());

    // Compare two LocalDate for before and after
    System.out.println("Today is before 01/01/2015? " + today.isBefore(LocalDate.of(2015, 1, 1)));

    // Create LocalDateTime from LocalDate
    System.out.println("Current Time=" + today.atTime(LocalTime.now()));

}

From source file:Main.java

public static void main(String[] args) {

    // the current date
    LocalDate currentDate = LocalDate.now();

    // 2014-02-10
    LocalDate tenthFeb2014 = LocalDate.of(2014, Month.FEBRUARY, 10);

    // months values start at 1 (2014-08-01)
    LocalDate firstAug2014 = LocalDate.of(2014, 8, 1);

    // the 65th day of 2010 (2010-03-06)
    LocalDate sixtyFifthDayOf2010 = LocalDate.ofYearDay(2010, 65);

    // times, e.g. 19:12:30.733

    LocalTime currentTime = LocalTime.now(); // current time
    LocalTime midday = LocalTime.of(12, 0); // 12:00
    LocalTime afterMidday = LocalTime.of(13, 30, 15); // 13:30:15

    // 12345th second of day (03:25:45)
    LocalTime fromSecondsOfDay = LocalTime.ofSecondOfDay(12345);

    // dates with times, e.g. 2014-02-18T19:08:37.950
    LocalDateTime currentDateTime = LocalDateTime.now();

    // 2014-10-02 12:30
    LocalDateTime secondAug2014 = LocalDateTime.of(2014, 10, 2, 12, 30);

    // 2014-12-24 12:00
    LocalDateTime christmas2014 = LocalDateTime.of(2014, Month.DECEMBER, 24, 12, 0);

    // current (local) time in Los Angeles
    LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles"));

    // current time in UTC time zone
    LocalTime nowInUtc = LocalTime.now(Clock.systemUTC());

    System.out.println("date/time creation: currentDate: " + currentDate);
    System.out.println("date/time creation: tenthFeb2014: " + tenthFeb2014);
    System.out.println("date/time creation: firstAug2014: " + firstAug2014);
    System.out.println("date/time creation: sixtyFifthDayOf2010: " + sixtyFifthDayOf2010);
    System.out.println("date/time creation: currentTime: " + currentTime);
    System.out.println("date/time creation: midday: " + midday);
    System.out.println("date/time creation: afterMidday: " + afterMidday);
    System.out.println("date/time creation: fromSecondsOfDay: " + fromSecondsOfDay);
    System.out.println("date/time creation: currentTimeInLosAngeles: " + currentTimeInLosAngeles);
    System.out.println("date/time creation: currentDateTime: " + currentDateTime);
    System.out.println("date/time creation: secondAug2014: " + secondAug2014);
    System.out.println("date/time creation: christmas2014: " + christmas2014);
}

From source file:Main.java

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

    int day = 10;
    LocalDate date = LocalDate.of(Year.now().getValue(), month, day);

    // Invoking the query without using a lambda expression.
    Boolean isFamilyVacation = date.query(new FamilyVacations());

    // Invoking the query using a lambda expression.
    Boolean isFamilyBirthday = date.query(FamilyBirthdays::isFamilyBirthday);

    if (isFamilyVacation.booleanValue() || isFamilyBirthday.booleanValue())
        System.out.printf("%s is an important date!%n", date);
    else/*  w  w w .  java  2  s . co m*/
        System.out.printf("%s is not an important date.%n", date);
}