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 How to change a date from 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 "How to change a date from a String?" Watch "How to change a date from a String?" New topic
Author

How to change a date from a String?

Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Hey everyone,

I have been looking at the API to see if I can change a string (representation of a date) to a date, so that I can manipulate the date, then set it back to a String.

ok, I know I can confuse.

I have a gui, that has todays date in a JTextArea, I have a button that opens up a date picking calendar so that I can pick a date, and send that date to the JTextArea, so that the date is updated.
All is working really well here.

but I have buttons that I want to move the date up or down by one day at a time. Currently looking like Friday 16 March 2007

so the JTextArea has a String to show that date.

I seen in SimpleDateFormat class there is a method called parse, this takes a String (the one I show currently) and ParsePosition as arguments.

I am really confused with the ParsePosition, I have read through this part of the API and I am still stumped.

please could someone help?

davy


How simple does it have to be???
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18754
    
  40

If the string that you are trying to parse contains the string representation of the date, and nothing else, you don't need to use the parse position. Just call the parse() method that takes the single string parameter.

As long as you define the pattern to match the date format of your string, it should work fine.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
jQuery in Action, 2nd edition
 
subject: How to change a date from a String?