- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 represent fixed date like credit card expiry, YearMonth 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
- Java Program for credit card number validation
- How to set cookies expiry date in JavaScript?
- How to validate expiry date on a MySQL query?
- How to check windows certificate expiry date using PowerShell?
- Java 8 Clock fixed() method
- How to convert Date to String in Java 8?
- Top credit card security tips while shopping online
- How to get a particular date in Java 8?
- How to get the certificate's start and expiry date using PowerShell?
- Python program to check credit card number is valid or not
- How to find Date after 1 week in java 8?
- What are Credit card Frauds and characteristics that allow fraud?
- How to see if a date is before or after another date in Java 8?
- MySQL query to find expiry date (record) from the next 2 days?
- How to validate given date formats like MM-DD-YYYY using regex in java?
