Skip to content
Related Articles
Open in App
Not now

Related Articles

DateFormatSymbols getEras() Method in Java with Examples

Improve Article
Save Article
Like Article
  • Last Updated : 03 Jun, 2019
Improve Article
Save Article
Like Article

The getEras() Method of DateFormatSymbols class in Java is used to get the Era strings in string format. For eg., “BC” and “AD”.

Syntax:

public String[] getEras()

Parameters: The method does not take any parameters.

Return Values: The method returns the Era strings.

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




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

Output:

EraString 0 = BC
EraString 1 = AD

Example 2:




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

Output:

EraString 0 = BC

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


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!