I have a string in the form of Fri Jul 17 12:41:20 IST 2020 and I want to persist this in MS SQL server table with column type DATETIME.
For that, I first need to convert the above string into Date POJO.
I have a string in the form of Fri Jul 17 12:41:20 IST 2020 and I want to persist this in MS SQL server table with column type DATETIME.
For that, I first need to convert the above string into Date POJO.
You can also store long if needed but there is a basic conversion on string to Date or Long.
//Fri Jul 17 12:41:20 IST 2020
public static Long getDateTime(String input){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
try {
Date date = simpleDateFormat.parse(input);
return date.getTime();
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args){
System.out.println(DateConverter.getDateTime("Fri Jul 17 12:41:20 IST 2020"));
}