How to convert string date to Timestamp in java?

后端 未结 6 816
臣服心动
臣服心动 2020-12-03 13:15

I want to convert string Date into Timestamp in java. The following coding i have written.I have declare the date for date1 is: 7-11-11 12:13:14.

SimpleDateF         


        
6条回答
  •  春和景丽
    2020-12-03 14:02

    Use below code to convert String Date to Epoc Timestamp. Note : - Your input Date format should match with SimpleDateFormat.

    String inputDateInString= "8/15/2017 12:00:00 AM";
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyy hh:mm:ss");
    
    Date parsedDate = dateFormat.parse("inputDateInString");
    
    Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());
    
    System.out.println("Timestamp "+ timestamp.getTime());
    

提交回复
热议问题