当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to convert 'time' from an HTML textbox to sql time?

问题描述:

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();
    }
分享给朋友:
您可能感兴趣的文章:
随机阅读: