import java.util.Date; public class date_solution_a { public static void main (String[] args) { // Create four dates Date date1 = new Date ("17 Nov 1998 2:12"); Date date2 = new Date ("17 Nov 1998 0:40"); Date date3 = new Date ("17 Nov 1998 12:11"); Date date4 = new Date ("17 Nov 1998 23:59"); // print each of the four dates print_date (date1); print_date (date2); print_date (date3); print_date (date4); } public static void print_date (Date d) { // Get the year int year = d.getYear (); // Get the month int month = d.getMonth () + 1; // Get the date int date = d.getDate (); // Get the hours int hours = d.getHours (); // Get the minutes int minutes = d.getMinutes (); // Figure out whether it is "am" or "pm" String am_pm; if (hours < 12) { am_pm = "am"; } else { am_pm = "pm"; // Adjust the 24 hour clock to a 12 hour clock hours -= 12; } // 0 hours is the same as 12 o'clock if (hours == 0) hours = 12; // Create a string containing the time String time = hours + ":" + minutes + am_pm + " on " + month + "/" + date + "/" + year; // Print the time System.out.println (); System.out.println ("The time is: " + time); System.out.println (); } }