Convert String to java.sql.Date and java.sql.Time

前端 未结 2 930
难免孤独
难免孤独 2021-01-25 07:41

If I have a method like this:

public static String convertDateTimeToString(DateTime dt) {
    return dt.getDate() + \" \" + dt.getTime();
}

Whi

相关标签:
2条回答
  • 2021-01-25 08:39

    You can use the valueOf method of java.sql.Time to convert a String into a java.sql.Time, and use the valueOf method of java.sql.Date to convert a String into a java.sql.Date

    0 讨论(0)
  • 2021-01-25 08:41

    Look at SimpleDateFormat class. Here's a tutorial.

    You'll need something like this:

    String datetimeString;
    Date result;
    SimpleDateFormat formatter = new SimpleDateFormat("EEE d MMM yy hh:mm:ss");
    result = formatter.parse (datetimeString);
    
    0 讨论(0)
提交回复
热议问题