Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

format date in java

Thread view: 
dufffman@gmail.com - 17 Nov 2005 18:44 GMT
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,
Oliver Wong - 17 Nov 2005 18:50 GMT
> Hi,
>
[quoted text clipped - 3 lines]
>
> Thanks,

See java.text.DateFormat

http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html

   - Oliver
Rhino - 17 Nov 2005 20:23 GMT
> 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
zero - 17 Nov 2005 20:35 GMT
> most other countries don't display dates
> in the "November 13 2005" format.

Which can be very confusing - is 05-10-2005 October 5th or May 10th?
Dag Sunde - 18 Nov 2005 09:28 GMT
>> most other countries don't display dates
>> in the "November 13 2005" format.
>
> 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

Signature

Dag.

Roedy Green - 17 Nov 2005 20:47 GMT
>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".

see http://mindprod.com/jgloss/calendar.html

See SimpleDateFormat
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.