问题描述:

I have this text box in HTML.

<input id="textinput" name="textTime" type="time" class="form-control input-md" >

The format of the input box in the browser looks like this (hh:mm AM/PM).

How do I convert this to a Time object in Java?

This code didn't work so far. It resulted an empty output

String timeRecorded=request.getParameter("textTime");

DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");

timeRecorded1 = (Date)formatter.parse(timeRecorded);

网友答案:
 SimpleDateFormat format= new SimpleDateFormat("hh:mm:ss a");
    String yourtime= request.getParameter("textTime").toString();

    try
    {
      Date date = format.parse(yourtime);

      System.out.println(format.format(date));
    }

    catch (Exception e)
    {
      e.printStackTrace();
    }
相关阅读:
Top