title: How to convert string to date object in java
body: <p>I have a string in this format
  <code>String oldstring = "Mar 19 2018 - 14:39";</code></p>
  
  <p>How to convert this string to java object so that I get time and mins from date object.</p>
  
  <p>I have tried like this,</p>
  
  <pre><code>import java.util.Date;
  import java.text.SimpleDateFormat;
  import java.text.ParseException;
  
  public class DateEg {
      public static final void main(String[] args) {
          SimpleDateFormat localDateFormat = new SimpleDateFormat("HH:mm");
      String oldstring = "Mar 19 2018 - 14:39";
          String time = localDateFormat.format(oldstring);
          System.out.println(time);
      }
  }
  </code></pre>
  
  <p>But getting error, saying <code>Cannot format given Object as a Date</code></p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
      at java.base/java.text.DateFormat.format(DateFormat.java:332)
      at java.base/java.text.Format.format(Format.java:158)
      at DateEg.main(DateEg.java:9)
  </code></pre>
  
  <p>Is it possible to parse this string format in java?</p>