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:
- I was looking for this - Thanks
anonymous 24 Apr 2022 12:04:16 GMT
- Further comments disabled!
More Posts related to Java,
- [Fix] java.time.zone.ZoneRulesException: Unknown time-zone ID
- Parse XML file in Java using DOM Parser
- Java equals method - Tutorial
- [Program] How to read three different values using Scanner in Java
- Java: The value of the local variable string is not used
- Display Output in Java Console as a Table
- How to detect Operating System using Java code
- Java 8 Streams map() with examples
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Add newline character Java code example (\r \n \r\n)
- List of Java Major Minor Version Numbers
- IntelliJ Keyboard Shortcut to remove unused imports [Java]
- Java - Check if array contains the value
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- XmlRpcException ConnectException connection refused error
- Create a Zip file using Java Code programmatically
- List of jar files for Jax-ws (SOAP) based Java Web Services
- How to fix Java HTTP java.net.UnknownHostException
- List of jars required for Struts2 project
- [fix] java: incompatible types: double cannot be converted to java.lang.Integer Generics
- Maven BUILD FAILURE: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin
- Get the current timestamp in Java
- java: unclosed string literal [Error]
More Posts:
- [Fix] Microsoft Teams a JavaScript error occurred in the main process Error - Teams
- Android Disable EditText from Auto Focus on Activity load - Android
- Multiple line editing in Notepad++ - NotepadPlusPlus
- How to remove username from Mac Menu Bar? - MacOS
- clear is not recognized as an internal or external command operable program or batch file. - DOS
- How to adjust MacBook Desktop icons size - MacOS
- [macOS] How to search or view previous terminal command history - MacOS
- How to make Text in TextView bold and italic in Android - Android