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

Description

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


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

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

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



PreviousNext

Related