We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Introduction
- Java Date and Time
- Discussions
Java Date and Time
Java Date and Time
Sort by
recency
|
1510 Discussions
|
Please Login in order to post a comment
In Java 15 solution
In this code there is one cofusion every begginer will face that is why month -1 is there in this line of code:
calendar.set(year, month-1, day);Explanation : Calendar class represents months as 0-indexed.
So January is 0, February is 1, ... November is 10 and December is 11. So if we are giving Aughust which 8th month. you must pass 7 (i.e., 8 - 1).
as
Java 8 solution:
public static String findDay(int month, int day, int year) { LocalDate date = LocalDate.now(); if(year >2000 && year < 3000) { date = LocalDate.of(year, month, day);
} return date.getDayOfWeek().toString(); }