Java LocalDate class - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
corejavatutorial

Java LocalDate class

Java LocalDate class

In this tutorial you learn Java LocalDate class is an immutable class that represents Date with a default format of yyyy-MM-dd. It inherits Object class and implements the ChronoLocalDate interface

Java LocalDate class declaration

Let's see the declaration of java.time.LocalDate class.


  • public final class LocalDate extends Object   
  • implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable  
  • Java LocalDate Example

    import java.time.LocalDate;  
    1. public class LocalDateExample {  
    2.   public static void main(String[] args) {  
    3.     LocalDate date = LocalDate.now();  
    4.     LocalDate yesterday = date.minusDays(1);  
    5.     LocalDate tomorrow = yesterday.plusDays(2);  
    6.     System.out.println("Today date: "+date);  
    7.     System.out.println("Yesterday date: "+yesterday);  
    8.     System.out.println("Tommorow date: "+tomorrow);  
    9.   }  
    10. }  
    Output:
    Today date: 2017-01-13
    Yesterday date: 2017-01-12
    Tommorow date: 2017-01-14

    Java LocalDate Example: isLeapYear()

    1. import java.time.LocalDate;  
    2. public class LocalDateExample {  
    3.   public static void main(String[] args) {  
    4.     LocalDate date1 = LocalDate.of(2017113);  
    5.     System.out.println(date1.isLeapYear());  
    6.     LocalDate date2 = LocalDate.of(2016923);  
    7.     System.out.println(date2.isLeapYear());  
    8.   }  
    9. }  
    Output:
    false
    true

    Java LocalDate Example: atTime()

    1. import java.time.*;  
    2. public class LocalDateExample {  
    3.   public static void main(String[] args) {  
    4.     LocalDate date = LocalDate.of(2017113);  
    5.     LocalDateTime datetime = date.atTime(1,50,9);      
    6.     System.out.println(datetime);   
    7.   }  
    8. }  
    Output:
    2017-01-13T01:50:09

    About Mariano

    I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

    0 comments:

    Featured post

    Political Full Forms List

    Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

    Powered by Blogger.