format date in java

D

dufffman

Hi,

Simple java question. If my program takes in a date in the format,
yyyyMMdd, is there anyway I could output this date in java, in the
format, "November 13th 2005".

Thanks,
 
R

Rhino

Hi,

Simple java question. If my program takes in a date in the format,
yyyyMMdd, is there anyway I could output this date in java, in the
format, "November 13th 2005".
You probably can't get the 'th' part of the date using existing Java
techniques; I don't think there's any existing method you can use to get the
'th' in '13th' or the 'st' in '1st' or the 'nd' in '2nd'. But you could add
that part yourself with a simple if or switch statement that adds the
appropriate fragment once you've formatted the date as "November 13 2005" or
whatever. As Oliver Wong says in his reply, DateFormat is the approach you
should use. See also the SimpleDateFormat class for an explanation of Date
and Time Patterns.

If your application is going to have an international audience, you might
want to have a look at the Internationalization and Localization trail in
the Java Tutorial; most other countries don't display dates in the "November
13 2005" format.

Rhino
 
D

Dag Sunde

zero said:
Which can be very confusing - is 05-10-2005 October 5th or May 10th?

Which is why you should strive for either nationalize it to the
long string format, or use the ISO Date format.

Ie. (Norway):
13. November, 2005
(US):
November 13 2005

(ISO, any country):
2005-11-13
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top