Example usage for java.time LocalDate getYear

List of usage examples for java.time LocalDate getYear

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Gets the year field.

Usage

From source file:Main.java

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

    System.out.println(a.getYear());
}

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);//  w w w. j a va2s .  com
    Month month = localDate.getMonth();
    System.out.println(month);

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

}

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   w  w  w.  j a v  a 2s. c om*/

}

From source file:Main.java

public static void main(String[] args) {
    // Human Readable
    LocalDate date = LocalDate.now();
    System.out.println(String.format("%s-%s-%s", date.getYear(), date.getMonthValue(), date.getDayOfMonth()));

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, 2, 15); // 2014-02-15
    System.out.println(date.getYear()); // 2014
    System.out.println(date.getDayOfYear()); // 46
    System.out.println(date.lengthOfYear()); // 365
    System.out.println(date.isLeapYear()); // false

    Year year_2014 = Year.of(2014);
    System.out.println(year_2014.isLeap()); // false
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    System.out.println(String.format("Year : %s Month : %s day : %s", today.getYear(), today.getMonthValue(),
            today.getDayOfMonth()));//from   ww  w  .  j  a  v a2  s  .  c  o  m

    LocalDateTime time = LocalDateTime.now();
    System.out.println(
            String.format("Hour : %s Mins : %s Sec : %s", time.getHour(), time.getMinute(), time.getSecond()));

}

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) {
    Period p = Period.between(LocalDate.of(2009, Month.JANUARY, 21), LocalDate.of(2019, Month.JANUARY, 21));

    System.out.println(p.get(ChronoUnit.DAYS));

    LocalDate today = LocalDate.now();
    LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);

    LocalDate nextBDay = birthday.withYear(today.getYear());

    nextBDay = nextBDay.plusYears(1);/*  w  w  w .ja v a 2s.c  om*/

    p = Period.between(today, nextBDay);
    long p2 = ChronoUnit.DAYS.between(today, nextBDay);
    System.out.println(p.getMonths() + " months");
    System.out.println(p.getDays() + " days");
}

From source file:Main.java

public static void main(String[] args) {

    LocalDate today = LocalDate.now();
    LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);

    LocalDate nextBDay = birthday.withYear(today.getYear());

    //If your birthday has occurred this year already, add 1 to the year.
    if (nextBDay.isBefore(today) || nextBDay.isEqual(today)) {
        nextBDay = nextBDay.plusYears(1);
    }//  w  w  w .j a v  a  2  s . c o  m

    Period p = Period.between(today, nextBDay);
    long p2 = ChronoUnit.DAYS.between(today, nextBDay);
    System.out.println("There are " + p.getMonths() + " months, and " + p.getDays()
            + " days until your next birthday. (" + p2 + " total)");
}

From source file:cz.pichlik.goodsentiment.MockDataGenerator.java

public static LocalDateTime generateTimestamp(LocalDate seed) {
    return of(seed.getYear(), seed.getMonth(), seed.getDayOfMonth(), 0, 0).plusHours(rg().nextInt(23))
            .plusMinutes(rg().nextInt(59)).plusSeconds(rg().nextInt(59));
}