Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Convert String to Date

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to java, but familar enough with programming, I thought I should post in intermediate, I hope someone here can help. My question is how to convert a string to a date. I am retreiving a month, from a drop down that I have created full with all 12 months. This is returned as a string. I need this with another text field where they enter the four digit year to turn into a date field. First with the first of the month and then with the last day of the month. Example
Drop down selection: "March"
Text entry for year: "2002"
I need it to look like this 01-MAR-2003 and 31-MAR-2003 in order for me to insert it into the database.
Let me know if you can help.
Thanks.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you elaborate a bit? It looks like you just want to convert a few strings to a single string in a certain format. Is that correct?
 
Andrea Corbally
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I believe that is what I want to do. I have an array of months that I need to turn into the date field (first day of the month and last day of the month) based upon the month they select.
Ex:
They choose April from the drop down. I want that to convert to 01-APR-2003
Does that make sense? It is a string and has no date value. I need to determine what month they choose and add the day and year to it.
 
a young
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I'm still not sure about a few things but I wrote up some sample code that may help:

This code assumes you're using JTextBox and JComboBox to get the information. I left the date out because I wasn't sure how you were retrieving it.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a couple of Date Utility methods laying around here, they should help you out:

to parse the date, you could use the SimpleDateFormat:

Jamie
[ August 05, 2003: Message edited by: Jamie Robertson ]
 
Andrea Corbally
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all of your comments. I have gotten my string down to "-MAR-2003". I now need to convert it into a date and add the day. So it would look like "01-MAR-2003" and "31-MAR-2003". Any ideas on how I can do that?
 
a young
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post some code snipets or something? Your requests still have me confused.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic