File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes formatting a string (that is secretly a date) yet as a string... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "formatting a string (that is secretly a date) yet as a string..." Watch "formatting a string (that is secretly a date) yet as a string..." New topic
Author

formatting a string (that is secretly a date) yet as a string...

Matt Horton
Ranch Hand

Joined: Feb 06, 2002
Posts: 107
Is this the 'proper' way to do this:

Is there a way for me to bypass making a date object, or a better way to convert b/w dates and strings?
Thanks in advance.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
The SimpleDateFormat is the easiest way to convert between Dates and Strings, but what you have posted won't give you the results desired:

What you want is something like the convertDate funtion below:


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
If you were just hell-bent on not making a Date object, you could write your own formatter using regular expressions and/or a few String.substring() and String.charAt() invocations.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: formatting a string (that is secretly a date) yet as a string...
 
Similar Threads
Doubt in SimpleDateFormat
Date Converting String to Date
converting dateformat compatible to oracle date
Date Formatting Help
Converting dates to GMT