Display current time in 12 hour format with AM/PM

To display the current time in 12-hour format with AM/PM in Java, you can use the SimpleDateFormat class and the Calendar class.

Here's an example of how you can use these classes to display the current time in 12-hour format with AM/PM:

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
  public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm a");
    System.out.println(timeFormat.format(calendar.getTime()));
  }
}

This code defines a main method that creates a Calendar object and a SimpleDateFormat object. The Calendar object is used to get the current time, and the SimpleDateFormat object is used to format the time in the desired format. The formatted time is then printed to the console.

The SimpleDateFormat pattern "hh:mm a" specifies that the time should be formatted as hours (in 12-hour format), minutes, and AM/PM indicator.

I hope this helps! Let me know if you have any questions.