1 java simpledateformat java.util.date
我试图将"12-Jun-2013"日期转换为"12-06-2013",但它给了我例外.
String req="12-Jun-2013"
SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MMM/yyyy",Locale.UK);
try {
Date date = (Date) sdfSource.parse(req);
SimpleDateFormat sdfDestination = new SimpleDateFormat("dd-MM-yyyy",Locale.UK);
req = sdfDestination.format(date);
System.out.println("final object"+req);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我越来越异常了
java.text.ParseException: Unparseable date: "12-Jun-2013"
Run Code Online (Sandbox Code Playgroud)
Mic*_*tha 11
你的来源SimpleDateFormat应该是
SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MMM-yy",
Locale.UK);
Run Code Online (Sandbox Code Playgroud)
你的目的地SimpleDateFormat应该是
SimpleDateFormat sdfDestination = new SimpleDateFormat(
"dd-MM-yyyy", Locale.UK);
Run Code Online (Sandbox Code Playgroud)