This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to change a date from a String?  RSS feed

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?

Henry Wong
Posts: 23283
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.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!