-2

Possible Duplicate:
how to convert java string to Date object

I have a form in which I insert a time in the form of : 10:19 as a String. How can I convert this to the corresponding Time object?

Community
  • 1
  • 1
Sergiu
  • 2,502
  • 6
  • 35
  • 57
  • http://stackoverflow.com/questions/6510724/how-to-convert-java-string-to-date-object – Jacob Jul 14 '11 at 07:23
  • What happened to using Google these days? – Buhake Sindi Jul 14 '11 at 07:24
  • @Gentleman no reason to downvote this. every question on stackoverflow can be answered by using a search-engine yourself and the level at which you can do this only depends on your experience, easy questions are not a bad thing i think – Bernd Elkemann Jul 14 '11 at 07:27
  • @eznme, I never downvoted this question or any question that requires search-engine searches. Neither did I request to close this question. Don't just assume that everyone that comments, do downvote or vote to close the question. – Buhake Sindi Jul 14 '11 at 07:30
  • Sorry for posting. Will never do this again(on easy questions) since it seems it bothers you people. – Sergiu Jul 14 '11 at 07:36
  • 3
    @Sergiu, we are not against easy post. Many post, like the one you posted, have already been answered before. We suggest looking at **Related* * section (right-side of this post) to see if any of the past quesstions were answered. Also, Google search definitely can come up with results that fit your criteria1 :-D – Buhake Sindi Jul 14 '11 at 07:54

4 Answers4

3

You need to parse the string into a Date object. You could use SimpleDateFormat.

Vlad
  • 10,602
  • 2
  • 36
  • 38
1

Use SimpleDateFormat object.

Example:

DateFormat df = new SimpleDateFormat("HH:mm"); 
Date time;
try {
    time = df.parse("10:19");
} catch (ParseException e) {
    e.printStackTrace();
}
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

Use SimpleDateFormat that convert a string in a Calendar object or formats a Calendar object into a string

Daniel
  • 30
  • 1
  • 6
0

See the next links:

Java string to date conversion

http://www.roseindia.net/java/java-conversion/StringToDate.shtml

It was just Google.

Community
  • 1
  • 1
elvenbyte
  • 776
  • 1
  • 17
  • 34