File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Convert String to Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert String to Date" Watch "Convert String to Date" New topic
Author

Convert String to Date

Andrea Corbally
Greenhorn

Joined: Jul 28, 2003
Posts: 7
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.
a young
Greenhorn

Joined: Aug 05, 2003
Posts: 11
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

Joined: Jul 28, 2003
Posts: 7
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

Joined: Aug 05, 2003
Posts: 11
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.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Jul 28, 2003
Posts: 7
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

Joined: Aug 05, 2003
Posts: 11
Could you post some code snipets or something? Your requests still have me confused.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert String to Date
 
Similar Threads
Passing Date from HTML Form to JSP/Action Handler
How to set date in mysql using prepared statement?
Arranging the element in TreeMap
how to fetch values of elements on same page
Parsing a date from arbitrary text.