title: Servlet get date and time
body: <p>I'm using the following code to get the date and time</p>
  
  <pre><code>public class offer extends HttpServlet {
  
  
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
  
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
  
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;Servlet offer&lt;/title&gt;");
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;h1&gt; sv sugar mills&lt;/h1&gt;");
          doPost(request,response);
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
  
      } finally {
          out.close();
      }
  } 
  
   @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
       response.setContentType("text/html;charset=UTF-8");
       PrintWriter out = response.getWriter();
       java.sql.Date sqlDate=null,ofrmonth=null,ctime=null;
  
      dat="14/02/2013";
      try
      {
       java.util.Date date=new SimpleDateFormat("dd/MM/yyyy").parse(dat);
       //ctime=new java.sql.Date(date.getTime());
       sqlDate = new java.sql.Date(date.getTime());
       out.println(sqlDate);
       out.Println(ctime);
      }
      catch(Exception e)
      {
       out.println(e);
      }
   }
  @Override
  public String getServletInfo() {
      return "Short description";
  }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  
  <p>Here, the util.Date variable date is displayed as "Thu Feb 14 00:00:00 IST 2013". So I get the sql.Date easily as "2013-02-14". Also, I want to get the time from it. In the ctime variable I want to get the time and display it. The format should be 24hours format. But I don't know how to get it. </p>
  
  <p>I've used some functions like getHours() and getDate(), but I couldn't found the solution. Can someone help me to get the time. Thanks in advance</p>
  
  <p>I need the time as 00:00:00 (hh:mm:ss)</p>