
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to implement java.time.LocalDate using JShell in Java 9?
JShell is a REPL (Read-Eval-Print-Loop) interactive tool introduced in Java 9 that takes input, evaluates it, and returns output to a user.
java.util.LocalDate class provides a number of methods to retrieve Date information: Day/Month/Year and related attributes Date meta-information: Classification-related information such as whether a leap year, etc. LocalDate class is immutable, and we can use different methods provided to add and subtract days, months, and years. Each of these returns a new instance of LocalDate.
In the below two code snippets, we can able to print different operations using LocalDate class.
Snippet-1
jshell> import java.time.*; jshell> LocalDate today = LocalDate.now() today ==> 2020-04-22 jshell> today.getYear() $3 ==> 2020 jshell> today.getDayOfWeek() $4 ==> WEDNESDAY jshell> today.getDayOfMonth() $5 ==> 22 jshell> today.getDayOfYear() $6 ==> 113 jshell> today.getMonth() $7 ==> APRIL jshell> today.getMonthValue() $8 ==> 4 jshell> today.isLeapYear() $9 ==> true jshell> today.lengthOfYear() $10 ==> 366 jshell> today.lengthOfMonth() $11 ==> 30
Snippet-2
jshell> today.plusDays(50) $12 ==> 2020-06-11 jshell> today.plusMonths(50) $13 ==> 2024-06-22 jshell> today.plusYears(50) $14 ==> 2070-04-22 jshell> today.minusYears(50) $15 ==> 1970-04-22 jshell> LocalDate yesterYear = today.minusYears(50) yesterYear ==> 1970-04-22 jshell> today today ==> 2020-04-22
- Related Articles
- How to implement an ArrayList using JShell in Java 9?
- How to implement JShell using JavaFX in Java 9?\n
- How to implement a String in JShell in Java 9?
- How to implement a lambda expression in JShell in Java 9?
- How to implement the encapsulation concept in JShell in Java 9?
- How to implement the Fibonacci series in JShell in Java 9?
- How to implement integer type conversion in JShell in Java 9?
- How to implement a Set interface in JShell in Java 9?
- How to implement relational and logical operators in JShell in Java 9?
- How to implement String utility and immutability in JShell in Java 9?
- How to implement HashMap, LinkedHashMap, and TreeMap in JShell in Java 9?
- How can we implement a map in JShell in Java 9?
- How to get the date and time in JShell in Java 9?
- How to debug JShell in Java 9?
- Using Variables in JShell of Java 9

Advertisements