我遇到了一个问题:尝试将 SimpleDateFormat 与用户输入一起使用...
public static void main(String[] args) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/YYYY",Locale.US);
sdf.setLenient(false);
Scanner myScanner = new Scanner(System.in);
String myDate;
out.print("Please enter today's date [MM/DD/YYYY]: ");
myDate = myScanner.next();
Date date = sdf.parse(myDate);
out.println("Today is : " + date);
} catch (ParseException e) { e.printStackTrace(); }
}
结果是这样的:
Please enter today's date [MM/DD/YYYY]: 09/21/2008
Today is : Sun Dec 30 00:00:00 EST 2007