This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 1817

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
Converting dates to GMT
Date Formatting Help
Doubt in SimpleDateFormat
Date Converting String to Date
converting dateformat compatible to oracle date