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;
- public class LocalDateExample {
- public static void main(String[] args) {
- LocalDate date = LocalDate.now();
- LocalDate yesterday = date.minusDays(1);
- LocalDate tomorrow = yesterday.plusDays(2);
- System.out.println("Today date: "+date);
- System.out.println("Yesterday date: "+yesterday);
- System.out.println("Tommorow date: "+tomorrow);
- }
- }
Output:
Today date: 2017-01-13
Yesterday date: 2017-01-12
Tommorow date: 2017-01-14
Java LocalDate Example: isLeapYear()
- import java.time.LocalDate;
- public class LocalDateExample {
- public static void main(String[] args) {
- LocalDate date1 = LocalDate.of(2017, 1, 13);
- System.out.println(date1.isLeapYear());
- LocalDate date2 = LocalDate.of(2016, 9, 23);
- System.out.println(date2.isLeapYear());
- }
- }
Output:
Java LocalDate Example: atTime()
- import java.time.*;
- public class LocalDateExample {
- public static void main(String[] args) {
- LocalDate date = LocalDate.of(2017, 1, 13);
- LocalDateTime datetime = date.atTime(1,50,9);
- System.out.println(datetime);
- }
- }
Output:
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:
Post a Comment