Aakash Patel Aakash Patel - 1 year ago 114
Java Question

How do i convert "HH:MM" format string to TimeStamp in java?

I have a string **09:28.**But i want to convert this string in TimeStamp object.
How can i do that?
Below is my coding.

Object d = getMappedObjectValue(reportBeamDataMap, ReportBeamConstant.DAT_STOPDATE);
Date stopDate1 = (Date)d;`
SimpleDateFormat printFormat = new SimpleDateFormat("hh:mm");`
String timeString = printFormat.format(stopDate1);`

Now I want above String in
TimeStamp(Only HH:MM)
. How to do that?

Answer Source

Please Use parse method to get Date Object and then construct Timestamp object.

 try {
    Timestamp timestamp = new Timestamp(printFormat.parse(timeString).getTime());
    } catch (ParseException e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download