wood burning stoves
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
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

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?


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

Joined: Sep 28, 2004
Posts: 20531

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link: http://aspose.com/file-tools
subject: How to change a date from a String?
jQuery in Action, 3rd edition