How to parse a string in java.sql.date

I have a line

String s = "01 NOVEMBER 2012"; 

then I want to parse it on sqlDate,

then I insert it into the database

can I parse this line in sqlDate?!?!

yup, sql date format is "yyyy-mm-dd"

+4
source share
1 answer

Use SimpleDateFormat to parse string date in java.util.Date

 java.util.Date utilDate = new SimpleDateFormat("dd MMM yyyy").parse("01 NOVEMBER 2012"); 

and then convert it to java.sql.Date with millis

 java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); 
+12
source

Source: https://habr.com/ru/post/1439210/


All Articles