Java Date parse String like "2020-01" to date
import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] argv) { String sMt = "2020-01"; System.out.println(convertStringToDate(sMt)); }//from w w w .jav a 2 s. c om public static Date convertStringToDate(String sMt) { try { java.util.Date utilDate = new SimpleDateFormat("yyyy-MM").parse(sMt); return utilDate; } catch (Exception e) { e.printStackTrace(); return null; } } }