Java : DateTime - Exercises and Solution


1. Write a Java program to count the number of days between two given years

View Solution

2. Write a Java program to print LocalDate yyyy-MM-dd

View Solution

3. Write a Java program to print LocalTime HH:mm:ss

View Solution

4. Write a Java program to print LocalTime and LocalDate yyyy-MM-dd HH:mm:ss

View Solution

5. Write a Java program to print ZonedDateTime E MMM yyyy HH:mm:ss.SSSZ

View Solution

6. Write a Java program to print OffsetTime HH:mm:ss,Z

View Solution

7. Write a Java program to display combine local date and time in a single object

View Solution

8. Write a Java program to display current date without time and current time without date

View Solution

9. Write a Java program to calculate the difference between two dates in days

View Solution

10. Write a Java program to get seconds since 1970

View Solution

11. Write a Java program to convert a unix timestamp to date

View Solution

12. Write a Java program to extract date, time from the date string

View Solution

13. Write a Java program to get today's date at midnight time

View Solution

14. Write a Java program to get the next and previous Friday

View Solution

15. Write a Java program to calculate your age

View Solution

16. Write a Java program to compute the difference between two datetime (Hours, Minutes, Milliseconds, Seconds and Nanoseconds)

View Solution

17. Write a Java program to compute the difference between two dates (Years, Months, Days)

View Solution

18. Write a Java program to convert a string to date

View Solution

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

View Solution

20. Write a Java program to get the information of a given time

View Solution

21. Write a Java program to get the information of current/given month

  • Current Month of Number : 6
  • Number of Days in Month : 30
  • Maximum Number of Days in Month : 30
  • First Month of the Quarter : APRIL
View Solution

22. Write a Java program to get the information of current/given year

  • Current Year : 2001
  • Is Current Year or leap Year ? false
  • Number of Days in the year : 365 days
View Solution

23. Write a Java program to display the dates in the specified formats

View Solution

24. Write a Java program to get the months remaining in the year

View Solution

25. Write a Java program to get the dates 10 days before and after today

View Solution

26. Write a Java program to get the current time in all the available time zones

View Solution

27. Write a Java program to get current timestamp

View Solution

28. Write a Java program to get year and months between two dates

View Solution

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

View Solution

30. Write a Java program to get a date after 2 weeks

View Solution

31. Write a Java program to add some hours to the current time

View Solution

32. Write a Java program to get the current local time

View Solution

33. Write a Java program to get a day of the week of a specific date

View Solution

34. Write a Java program to get localized day in week name

View Solution

35. Write a Java program to get Current Locale day in week name

View Solution

36. Write a Java program to get the number of days of a month

View Solution

37. Write a Java program to get the name of the first and last day of a month

View Solution

38. Write a Java program to calculate the first and last day of each week

View Solution

39. Write a Java program to get the last date of the month

View Solution

40. Write a Java program to get the last day of the current month

View Solution

41. Write a Java program to get current full date and time

View Solution

42. Write a Java program to get the current time in New York

View Solution

43. Write a Java program to get the minimum value of year, month, week, date from the current date of a default calendar

View Solution

44. Write a Java program to get the maximum value of the year, month, week, date from the current date of a default calendar

View Solution

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

View Solution

46. Write a Java program to create a Date object using the Calendar class

View Solution

47. Write a Java Program to Generate Month Calendar of Any Year

View Solution

48. Write a Java Program to Generate One Year Calendar

View Solution

49. Write a Java Program to Decrement a Month using the Calendar Class

View Solution

50. Write a Java Program to Increment a Month using the Calendar Class

View Solution

51. Write a Java Program to Get individual components of the current time

View Solution

52. Write a Java Program to Compare time using equals() method

View Solution

53. Write a Java Program to Compare time using compareTo() method

View Solution

54. Write a Java Program to Add years to the current date

View Solution

55. Write a Java Program to Add months to the current date

View Solution

56. Write a Java Program to Subtract days from the current date

View Solution

57. Write a Java Program to Add days to the current date

View Solution

58. Write a Java Program to Get the current day number of a month using the get() method of Calendar class

View Solution

59. Write a Java Program to Get the current year using the get() method of Calendar class

View Solution

60. Write a Java Program to Print the current date-time using Calendar class

View Solution

61. Write a Java Program to Create a LocalDate object from the object of Date class

View Solution

62. Write a Java Program to Parse individual components of date from the current date

View Solution

63. Write a Java Program to Parse individual components of date from a string

View Solution

64. Write a Java Program to Compare dates using the Date.equals() method

View Solution

65. Write a Java Program to Compare dates using Date.compareTo() method

View Solution

66. Write a Java Program to Get a date from milliseconds using the Date.setTime() method

View Solution

67. Write a Java Program to Get a date from milliseconds using Date() constructor

View Solution

68. Write a Java Program to Get milliseconds from the specified date

View Solution

69. Write a Java Program to Convert 'java.util.Date' into 'java.sql.Date'

View Solution

70. Write a Java Program to Get current system date and time in Java

View Solution

71. Write a Java Program to get elapsed time in seconds and milliseconds

View Solution



Basic Programs