Problems

Use the following problems to test your date and time programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:

  1. Converting a string to date and time: Write a program that exemplifies conversions between a string and date/time.
  2. Formatting date and time: Explain the format pattern for date and time.
  3. Getting the current date/time without time/date: Write a program that extracts the current date without the time or date.
  4. LocalDateTime from LocalDate and LocalTime: Write a program that builds a LocalDateTime from LocalDate object and LocalTime. It combines the date and time in a single LocalDateTime object.
  5. Machine time via an Instant class: Explain and give an example of the Instant API.
  6. Defining a period of time using date-based values (Period) and a duration of time using time-based values (Duration): Explain and give an example of the usage of the Period and Duration APIs.

 

  1. Getting date and time units: Write a program that extracts the date and time units (for example, extract from date the year, month, minute, and so on) from an object representing a date-time.
  2. Adding and subtracting to/from a date-time: Write a program that adds (and subtracts) an amount of time (for example, years, days, or minutes) to a date-time object (for example, add an hour to date, subtract 2 days from LocalDateTime, and so on).
  3. Getting all time zones with UTC and GMT: Write a program that displays all the available time zones with UTC and GMT.
  4. Getting the local date-time in all available time zones: Write a program that displays the local time in all the available time zones.
  5. Displaying date-time information about a flight: Write a program that displays information about a scheduled flight time of 15 hours and 30 minutes. More precisely, a flight from Perth, Australia to Bucharest, Europe.
  6. Converting a Unix timestamp to date-time: Write a program that converts a Unix timestamp to java.util.Date and java.time.LocalDateTime.
  7. Finding the first/last day of the month: Write a program that finds the first/last day of the month via JDK 8, TemporalAdjusters.
  8. Defining/extracting zone offsets: Write a program that reveals different techniques for defining and extracting zone offsets.
  9. Converting between Date and Temporal: Write a program that converts between Date and Instant, LocalDate, LocalDateTime, and so on.
  10. Iterating a range of dates: Write a program that iterates a range of given dates, day by day (with a step of a day).
  11. Calculating age: Write a program that calculates the age of a person.
  12. Start and end of a day: Write a program that returns the start and end time of a day.
  13. Difference between two dates: Write a program that calculates the amount of time, in days, between two dates.
  14. Implementing a chess clock: Write a program that implements a chess clock.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.198.81