aspose 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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...