SimpleDateFormat Era Example in java

This example shows you how to get the Era designator Using SimpleDateFormat object.

package com.java.connect.date;
 
import java.text.SimpleDateFormat;
import java.util.Calendar;
 
public class SimpleDateFormatEraExample {
    public static void main(String[] args) {
        // Get the simple date format object by passing the format in string
        SimpleDateFormat format = new SimpleDateFormat("G");
        // get the date in String format by passing current date
        // in format method of simple date format object
        Calendar originalDate = Calendar.getInstance();
        System.out.println("The original date is : " + originalDate.getTime());
        String dateString = format.format(originalDate.getTime());
        // Print the formated date.
        System.out.println("The Era of given date is : "+dateString);
    }
}

The output of above example will be as:

The original date is : Sat May 07 19:34:56 GMT 2011
The Era of given date is : AD