- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get a particular date in Java 8?
The java.time package of Java provides API’s for dates, times, instances and durations. It provides various classes like Clock, LocalDate, LocalDateTime, LocalTime, MonthDay, Year, YearMonth, etc. Using classes of this package you can get details related to date and time in much simpler way compared to previous alternatives.
Java.time.LocalDate − This class represents a date object without time zone in ISO-8601 calendar system. The now() method of this class obtains the current date from the system clock.
The of() method of java.time.LocalDate class accepts three integer parameters representing and year, a month of an year, day of a month and, returns the instance of the LocalDate object from the given details.
Example
Following Java program reads year, month and day values from the user and creates a Date object of the given date using the classes and methods java.time package of Java8.
import java.time.LocalDate; import java.util.Scanner; public class LocalDateJava8 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the year: "); int year = sc.nextInt(); System.out.println("Enter the month: "); int month = sc.nextInt(); System.out.println("Enter the day: "); int day = sc.nextInt(); //Getting the current date value LocalDate givenDate = LocalDate.of(year, month, day); System.out.println("Date: "+givenDate); } }
Output
Enter the year: 2019 Enter the month: 07 Enter the day: 24 Date: 2019-07-24
- Related Articles
- Get the day of week for a particular date in Java
- Set a GregorianCalendar object to a particular date in Java
- How to get particular date records from time stamp in Android sqlite?
- How to convert Date to String in Java 8?
- Java program to add a given time to a particular date
- How to get the current date in Java?
- How to see if a date is before or after another date in Java 8?
- How to find Date after 1 week in java 8?
- How to check Leap Year in Java 8 How to get current timestamp in Java 8?
- How to get current Time in Java 8?
- How to get a Date from year, month and day in Java?
- How to get a substring of a particular string in Java. Explain with an example.
- How to get the current date and time in Java?
- How to get current date/time in milli seconds in Java?
- How to get a particular anchor in a document in JavaScript?
