Aakash Patel Aakash Patel - 1 month ago 11
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

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) {
        e.printStackTrace();
    }