How to print out a date from the past

I am trying to print out a date from the past but I cant seem to get It,Lets use for example Independece Day, How would you write the code in order to print out that exact date?
[198 byte] By [rosas101a] at [2007-11-26 18:37:24]
# 1
Look at the [url= http://java.sun.com/javase/6/docs/api/index.html?java/util/Date.html]Date API[/url]
Djaunla at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...
# 2
Cuban Independence Day is 20 May, is that what you mean?
DrLaszloJamfa at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...
# 3
My bad, look at the [url= http://java.sun.com/javase/6/docs/api/index.html?java/util/Calendar.html]Calender API[/url] instead.
Djaunla at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...
# 4

> Look at the

> [url=http://java.sun.com/javase/6/docs/api/index.html?

> java/util/Date.html]Date API[/url]

Actually the Calendar class would be better to use, since you can set all the different fields from year to second, plus things like day of week, day of month, week of year, etc.

too slow

Message was edited by:

hunter9000

hunter9000a at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...
# 5
Calendar will give you a representation of the date, but to format it for printing,you'll probably use [url= http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html]SimpleDateFormat[/url].
DrLaszloJamfa at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...
# 6

This is part of the code Im using

SimpleDateFormat date = new SimpleDateFormat("independence day = ' MMMM d'th' yyyy");

Calendar cal = Calendar.getInstance();

cal.clear();

cal.set(1776, 6, 4);

im kind of new at this so what i cant do is put a print code because everything I have tried creates a compiler error

rosas101a at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...
# 7

SimpleDateFormat formatter = new SimpleDateFormat("MMMM dd, yyyy");

Calendar cal = Calendar.getInstance();

cal.clear();

cal.set(1902, Calendar.MAY, 20);

System.out.println(formatter.format(cal.getTime()));

Note that the month number is 0-based. O is January, 1 is February etc... So if you can it's a good idea to use constants like Calendar.MAY.

DrLaszloJamfa at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...
# 8
Also, the formatter string should not contain other text like "independence =", and I don't know of a way to ask it to automatically add "st", "nd", "rd" "th" etc... to a date.
DrLaszloJamfa at 2007-7-9 6:11:28 > top of Java-index,Java Essentials,Java Programming...