w3resource logo
Java Programming Exercises

Java Date, Calendar and Time: Exercises, Practice, Solution

Java Date, Time and Calendar Exercises [37 exercises with solution]

1. Write a Java program to create a Date object using the Calendar class. Go to the editor

Click me to see the solution

2. Write a Java program to get and display information (year, month, day, hour, minute) of a default calendar. Go to the editor

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

5. Write a Java program to get the current time in New York. Go to the editor

Click me to see the solution

6. Write a Java program to get current full date and time. Go to the editor

Click me to see the solution

7. Write a Java program to get the last day of the current month. Go to the editor

Click me to see the solution

8. Write a Java program to get the last date of the month. Go to the editor

Click me to see the solution

9. Write a Java program to calculate the first and last day of each week. Go to the editor

Click me to see the solution

10. Write a Java program to get the name of the first and last day of a month. Go to the editor

Click me to see the solution

11. Write a Java program to get the number of days of a month. Go to the editor

Click me to see the solution

12. Write a Java program to get localized day-in-week name. Go to the editor

Click me to see the solution

13. Write a Java program to get a day of the week of a specific date. Go to the editor

Click me to see the solution

14. Write a Java program to get the current local time. Go to the editor

Click me to see the solution

15. Write a Java program to add some hours to the current time. Go to the editor

Click me to see the solution

16. Write a Java program to get a date after 2 weeks. Go to the editor

Click me to see the solution

17. Write a Java program to get a date before and after 1 year compares to the current date. Go to the editor

Click me to see the solution

18. Write a Java program to check a year is a leap year or not. Go to the editor

Click me to see the solution

19. Write a Java program to get year and months between two dates. Go to the editor

Click me to see the solution

20. Write a Java program to get current timestamp. Go to the editor

Click me to see the solution

21. Write a Java program to get the current time in all the available time zones. Go to the editor

Click me to see the solution

22. Write a Java program to get the dates 10 days before and after today. Go to the editor

Click me to see the solution

23. Write a Java program to get the months remaining in the year. Go to the editor

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

27. Write a Java program to get the information of a given time. Go to the editor

Click me to see the solution

28. Write a Java program to display the date time information before some hours and minutes from current date time. Go to the editor

Click me to see the solution

29. Write a Java program to convert a string to date. Go to the editor

Click me to see the solution

30. Write a Java program to compute the difference between two dates (year, months, days). Go to the editor

Click me to see the solution

31. Write a Java program to compute the difference between two dates (Hours, minutes, milli, seconds and nano). Go to the editor

Click me to see the solution

32. Write a Java program to calculate your age. Go to the editor

Click me to see the solution

33. Write a Java program to get the next and previous Friday. Go to the editor

Click me to see the solution

34. Write a Java program to get today's date at midnight time. Go to the editor

Click me to see the solution

35. Write a Java program to extract date, time from the date string. Go to the editor

Click me to see the solution

36. Write a Java program to convert a unix timestamp to date in Java. Go to the editor

Click me to see the solution

37. Write a Java program to find seconds since 1970. Go to the editor

Click me to see the solution

Java Code Editor

More to Come !