DateFormatSymbols getAmPmStrings() Method in Java with Examples
Last Updated :
30 May, 2019
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:
import java.text.DateFormatSymbols;
public class DateFormat_Main {
public static void main(String args[])
{
int i;
String AMPM[]
= new DateFormatSymbols().getAmPmStrings();
for (i = 0 ; i < AMPM.length; i++) {
System.out.println( "Time " + i
+ " = " + AMPM[i]);
}
}
}
|
Output:
Time 0 = AM
Time 1 = PM
Example 2:
import java.text.DateFormatSymbols;
public class DateFormat_Main {
public static void main(String args[])
{
int i;
String AMPM[]
= new DateFormatSymbols().getAmPmStrings();
for (i = 0 ; i < AMPM.length / 2 ; i++) {
System.out.println( "Time " + i
+ " = " + AMPM[i]);
}
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#getAmPmStrings–
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...