title: java string to date conversion without seconds
body: <p>I have to convert string to date such that it should throw error when string is having seconds. For example if I am giving input string as "2015-08-12 12:24:08" I should get an error because I am giving seconds in the string(i.e., 08 here), whereas if I give input as "2015-08-12 12:24" I shouldn't get any error. How can I achieve that?</p>
  
  <p>I have tried below code</p>
  
  <pre><code>     String oldstring2 = "2015-08-12 12:24:08";
       Date date2 = null;
  try {
      date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(oldstring2);
      System.out.println(date2);
      System.out.println("success");
  } catch (ParseException e) {
      e.printStackTrace();
      System.out.println("error");
  }
  </code></pre>