Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to change a date from a String?

 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 22114
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic