Java LocalDate getEra() Method with Examples

This method is used to get the era of a date. For example, BC, AD, and CE. IsoChronology defines eras CE (Current Era) from year one onwards and BCE (Before Current Era) from year zero backward.

This method does not take any argument and returns an IsoEra enum value. The syntax of the method is given below.

Syntax

public IsoEra getEra()

Parameters:

It does not take any argument.

Return:

It returns an era of date.

Time for an Example:

Lets take an example to get era of a date using getEra() method. Here we have a year 2020 the represents Current Era, date that have year more than zero belongs to CE.

import java.time.LocalDate;
import java.time.chrono.IsoEra; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.of(2020, 2, 25);
		System.out.println(localDate);
		IsoEra era = localDate.getEra();
		System.out.println("Date era : "+era);
	}
}


2020-02-25
Date era : CE

Time for another Example:

A date that represents zero or less year belongs to BCE. Here we have a date that shows a year zero and returns BCE era.

import java.time.LocalDate;
import java.time.chrono.IsoEra; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.of(0000, 1, 01);
		System.out.println(localDate);
		IsoEra era = localDate.getEra();
		System.out.println("Date era : "+era);
	}
}


0000-01-01
Date era : BCE

Live Example:

Try with a live example, execute the code instantly with our powerful Online Java Compiler.