Thursday, February 12, 2026
HomeLanguagesJavaDateFormatSymbols getAmPmStrings() Method in Java with Examples

DateFormatSymbols getAmPmStrings() Method in Java with Examples

The getAmPmStrings() Method of DateFormatSymbols class in Java is used to get the AM’s and PM’s string format. For eg., “AM” and “PM”.

Syntax:

public String[] getAmPmStrings()

Parameters: The method does not take any parameters.

Return Values: The method returns the AM and PM in string format.

Below programs illustrate the use of getAmPmStrings() method.
Example 1:




// Java code to demonstrate getAmPmStrings()
  
import java.text.DateFormatSymbols;
  
public class DateFormat_Main {
    public static void main(String args[])
    {
        int i;
  
        // Initializing DateFormatSymbols
        String AMPM[]
            = new DateFormatSymbols().getAmPmStrings();
  
        for (i = 0; i < AMPM.length; i++) {
  
            // Displaying the AMPM
            System.out.println("Time " + i
                               + " = " + AMPM[i]);
        }
    }
}


Output:

Time 0 = AM
Time 1 = PM

Example 2:




// Java code to demonstrate getAmPmStrings()
  
import java.text.DateFormatSymbols;
  
public class DateFormat_Main {
    public static void main(String args[])
    {
        int i;
  
        // Initializing DateFormatSymbols
        String AMPM[]
            = new DateFormatSymbols().getAmPmStrings();
  
        for (i = 0; i < AMPM.length / 2; i++) {
  
            // Displaying the AMPM
            System.out.println("Time " + i
                               + " = " + AMPM[i]);
        }
    }
}


Output:

Time 0 = AM

Reference: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#getAmPmStrings–

RELATED ARTICLES

Most Popular

Dominic
32497 POSTS0 COMMENTS
Milvus
128 POSTS0 COMMENTS
Nango Kala
6869 POSTS0 COMMENTS
Nicole Veronica
11996 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12090 POSTS0 COMMENTS
Shaida Kate Naidoo
7009 POSTS0 COMMENTS
Ted Musemwa
7246 POSTS0 COMMENTS
Thapelo Manthata
6958 POSTS0 COMMENTS
Umr Jansen
6947 POSTS0 COMMENTS