Java Date parse String like "12:42" to date

Description

Java Date parse String like "12:42" to date


import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    String sMt = "12:42";
    System.out.println(convertStringToDate(sMt));
  }//from  w w  w. j a v a 2s .co  m

  public static Date convertStringToDate(String sMt) {
    try {
      java.util.Date utilDate = new SimpleDateFormat("HH:mm").parse(sMt);
      return utilDate;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
}



PreviousNext

Related