How to convert string date to Timestamp in java?

后端 未结 6 839
臣服心动
臣服心动 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:08

    You can even try this.

       String date="09/08/1980";    // take a string  date
        Timestamp ts=null;  //declare timestamp
        Date d=new Date(date); // Intialize date with the string date
        if(d!=null){  // simple null check
            ts=new java.sql.Timestamp(d.getTime()); // convert gettime from date and assign it to your timestamp.
        }
    

提交回复
热议问题