Java Date, Calendar and Time: Exercises, Practice, Solution
Java Date, Time and Calendar Exercises [46 exercises with solution]
1. Write a Java program to create a Date object using the Calendar class. Go to the editor
2. Write a Java program to get and display information (year, month, day, hour, minute) of a default calendar. Go to the editor
3. Write a Java program to get the maximum value of the year, month, week, date from the current date of a default calendar. Go to the editor
4. Write a Java program to get the minimum value of year, month, week, date from the current date of a default calendar. Go to the editor
5. Write a Java program to get the current time in New York. Go to the editor
6. Write a Java program to get current full date and time. Go to the editor
7. Write a Java program to get the last day of the current month. Go to the editor
8. Write a Java program to get the last date of the month. Go to the editor
9. Write a Java program to calculate the first and last day of each week. Go to the editor
10. Write a Java program to get the name of the first and last day of a month. Go to the editor
11. Write a Java program to get the number of days of a month. Go to the editor
12. Write a Java program to get localized day-in-week name. Go to the editor
13. Write a Java program to get a day of the week of a specific date. Go to the editor
14. Write a Java program to get the current local time. Go to the editor
15. Write a Java program to add some hours to the current time. Go to the editor
16. Write a Java program to get a date after 2 weeks. Go to the editor
17. Write a Java program to get a date before and after 1 year compares to the current date. Go to the editor
18. Write a Java program to check a year is a leap year or not. Go to the editor
19. Write a Java program to get year and months between two dates. Go to the editor
20. Write a Java program to get current timestamp. Go to the editor
21. Write a Java program to get the current time in all the available time zones. Go to the editor
22. Write a Java program to get the dates 10 days before and after today. Go to the editor
23. Write a Java program to get the months remaining in the year. Go to the editor
24. Write a Java program to display the dates in the following formats. Go to the editor
Sample format :
Default format of LocalDate=2016-09-16 16::Sep::2016 Default format of LocalDateTime=2016-09-16T11:46:01.455 16::Sep::2016 11::46::01 Default format of Instant=2016-09-16T06:16:01.456Z Default format after parsing = 2014-04-27T21:39:48
25. Write a Java program to get the information of current/given year. Go to the editor
Sample format :
Sample Output : Current Year: 2001 Is current year leap year? false Length of the year: 365 days
26. Write a Java program to get the information of current/given month. Go to the editor
Sample format :
Sample Output : Integer value of the current month: 2 Length of the month: 28 Maximum length of the month: 29 First month of the Quarter: JANUARY
27. Write a Java program to get the information of a given time. Go to the editor
28. Write a Java program to display the date time information before some hours and minutes from current date time. Go to the editor
29. Write a Java program to convert a string to date. Go to the editor
30. Write a Java program to compute the difference between two dates (year, months, days). Go to the editor
31. Write a Java program to compute the difference between two dates (Hours, minutes, milli, seconds and nano). Go to the editor
32. Write a Java program to calculate your age. Go to the editor
33. Write a Java program to get the next and previous Friday. Go to the editor
34. Write a Java program to get today's date at midnight time. Go to the editor
35. Write a Java program to extract date, time from the date string. Go to the editor
36. Write a Java program to convert a unix timestamp to date in Java. Go to the editor
37. Write a Java program to find seconds since 1970. Go to the editor
38. Write a Java program to calculate the difference between two dates in days. Go to the editor
39. Write a java program to convert String to date and time and vice a versa. Go to the editor
40. Write a Java program to display current date without time and current time without date. Go to the editor
41. Write a Java program to display combine local date and time in a single object. Go to the editor
42. Write a Java program to define a period of time using date-based values (Period) and a duration of time using time-based values (Duration). Go to the editor
43. Write a Java program to display all the available time zones with UTC and GMT. Go to the editor
44. Write a Java program to define and extract zone offsets. Go to the editor
45. Write a Java program to print yyyy-MM-dd, HH:mm:ss, yyyy-MM-dd HH:mm:ss, E MMM yyyy HH:mm:ss.SSSZ and HH:mm:ss,Z, format pattern for date and time. Go to the editor
46. Write a Java program to count the number of days between two given years. Go to the editor
Java Code Editor
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
Java: Tips of the Day
How to sort an ArrayList?
Collections.sort(testList); Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Ref: https://bit.ly/32urdSe
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework