Java Date Format AM PM

Chapter: Date and Time Last Updated: 14-05-2023 11:49:13 UTC


            /* ............... START ............... */
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static void main(String[] args) {
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a");
        String formattedDate = sdf.format(now);

                /* ............... END ............... */


14-05-2023 09:30:15 AM
Please note that the actual output will depend on the current date and time when you run the program.


  • In this example, the pattern "dd-MM-yyyy hh:mm:ss a" is used to format the date. The "a" represents the AM/PM marker. When you run this code, it will display the current date and time in the specified format, including the AM/PM indicator.
  • Note that the "hh" pattern is used for a 12-hour clock format, while "HH" is used for a 24-hour clock format.


Java Date Format AM PM, How to get am and pm in date format Java?, Java Program to Format Time in AM-PM format

Similar Programs Chapter Last Updated
Java Add Months To Date Date and Time 14-05-2023
Add Days To Date In Java example Date and Time 14-05-2023
Java Program To Calculate Days Between Two Dates Date and Time 16-04-2023
Java Program To Add Days To Date Date and Time 16-04-2023
How To Find Difference Between Two Dates In Java Date and Time 01-04-2023
Add Days To Date Java Example Date and Time 08-08-2021
Time Difference Between Two Timestamps In Java Date and Time 22-09-2018