开发者

Date/Time in java [duplicate]

This question already has answers here: Closed 11 years ago.

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. 开发者_如何学Python How can I convert this to the corresponding Time object?


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


Use SimpleDateFormat object.

Example:

DateFormat df = new SimpleDateFormat("HH:mm"); 
Date time;
try {
    time = df.parse("10:19");
} catch (ParseException e) {
    e.printStackTrace();
}


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


See the next links:

Java string to date conversion

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

It was just Google.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜