How to convert Date in String to Sql date?

2019-09-03 08:47发布

I have a date with String format "09-06-2011". I need to compare it with another date in java.sql.Date format "2011-06-30 00:00:00". How can I convert a String date to a sql date ?

2条回答
祖国的老花朵
2楼-- · 2019-09-03 09:34

Use java.text.DateFormat and java.text.SimpleDateFormat and its parse method. Be sure to setLenient(false).

查看更多
乱世女痞
3楼-- · 2019-09-03 09:49

Use str_to_date function in MySQL.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

Format:

mysql> SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y');
    -> '2013-05-01'
查看更多
登录 后发表回答