public static void main(String[]args) { //自己替换[] // Create a date formatter that can parse dates of // the form MM-dd-yyyy. SimpleDateFormat bartDateFormat = new SimpleDateFormat("MM-dd-yyyy");
// Create a string containing a text date to be parsed. String dateStringToParse = "9-29-2001";
try { // Parse the text version of the date. // We have to perform the parse method in a // try-catch constrUCt in case dateStringToParse // does not contain a date in the format we are eXPecting. Date date = bartDateFormat.parse(dateStringToParse);