In order to display the Era the date belongs to AD or BC for a date in Java you need to make use of the SimpleDateFormat class with the date pattern that makes use of G
Example: Display Era in Java date
package com.company;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) throws ParseException {
String beforeChrisDate = "22 01 -2020";
String annoDominiDate = "22 01 2021";
DateFormat simpleDateFormat = new SimpleDateFormat("dd MM yyyy");
DateFormat simpleDateFormatEra = new SimpleDateFormat("dd MM yyyy G");
Date bcDate = simpleDateFormat.parse(beforeChrisDate);
Date adDate = simpleDateFormat.parse(annoDominiDate);
System.out.println(simpleDateFormatEra.format(bcDate));
System.out.println(simpleDateFormatEra.format(adDate));
}
}
Output:
22 01 2021 BC
22 01 2021 AD
As you can see in the above example, we first created a string that holds the date in dd MM yyyy format, then we converted it into a Date object and while displaying the date we used the format dd MM yyyy G, the negative year is displayed with suffix BC - Before Christ and positive year is displayed as AD - Anno Domini.

Display Date with BC and AD Era Java
Comments:
- How to convert ad to bc, or bc to ad using Java era?
anonymous 19 Aug 2022 11:02:22 GMT
- I was looking for this - Thanks
anonymous 24 Apr 2022 12:04:16 GMT
- Further comments disabled!
More Posts related to Java,
- Java equals method - Tutorial
- Unbound classpath container: JRE System Library [JavaSE-1.7]
- Spring Boot: @RequestBody not applicable to method
- Java 8: Steam map with Code Examples
- Java Program: Random Number Generator
- Java java.time.Clock class code examples [Java Date Time API]
- Fix: type argument is not within bounds of type-variable T
- [Fix] java.net.MalformedURLException: unknown protocol
- Java 7 addSuppression() and getSuppression() Exception Handling
- Convert Java Array to ArrayList Code Example
- How to Word-Warp Console logs in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Remove Trailing zeros BigDecimal Java
- CRUD operations in Spring Boot + JDBC
- [Java Threads] Should we extend Thread Class or implement Runnable interface
- Json Serialization and Deserialization using Java Jackson
- Create simple struts2 project using maven commands
- How to install Java OpenJDK 11 on Alpine Linux
- Unsupported major.minor version 52.0 in java
- Error: Can not find the tag library descriptor for
- Java: Convert String to Binary
- How to run Java Unit Test cases with Apache Maven?
- Java: Testing Private Methods in JUnit using reflection API Example
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Java Join Strings with Comma Separator
More Posts:
- Git Fix: fatal: refusing to merge unrelated histories Error - Git
- [Fix] Instant java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years - Java
- Installing and using unzip Command to unzip a zip file using Terminal - Linux
- [Fix] Cannot connect to Microsoft SQL Server, Error: 18456 - Microsoft
- Check if a Java Date String is Valid or Not (Java 8) - Java
- Java Split String by Spaces - Java
- Tutorial Java SOAP WebServices JAS-WS with Eclipse J2EE IDE and Tomcat Server Part 1 - Java
- Fix: ZSH: cd: too many arguments (macOS) - zsh