Question:
Java: DateFormat. getDateInstance() does not handle eras (BC/AD)?
oldguy
2007-08-07 11:12:39 UTC
If you use the localized formats created by DateFormat. getDateInstance() they display BC dates as positive years without the BC, ie. indistinguishable from AD dates.

Manually creating a SimpleDateFormat for each Locale and for each style JUST to add the era designator seems less than ideal.

Does anyone have any suggestions? Or, can anyone suggest sites where this problem has been discussed?
Five answers:
2007-08-12 21:16:52 UTC
looks like no one was actually reading what you wrote. They answer before they have read the whole question and so there answers are pointless.





sorry, I don't know either.
vincentgl
2007-08-08 12:46:22 UTC
Did you try looking at java.text.SimpleDateFormat? It's a DateFormat subclass that can include the era designator (you specify the format pattern).
Zeus
2007-08-12 20:26:00 UTC
Check this site:

http://www.enseignement.polytechnique.fr/informatique/profs/Jean-Jacques.Levy/00/jdk1.1.8/docs/api/java.text.SimpleDateFormat.html



You may get the era designator using simbol 'G'

example:



SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy G");



Date test = new Date();



System.out.println("My Era > " + sdf.format(test));



My testing Output:

=============

My Era > 13/08/2007 AD



:)
?
2016-10-30 09:40:07 UTC
Dateformat.getdateinstance
Mitchell
2007-08-07 11:26:23 UTC
Try BCE for BC. BCE is the same as BC, but more formal (Before Common Era, I think)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...