I am using this code to parse a Date.
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat formatterParse = new SimpleDateFormat("yyyy-MM-dd");
String s = formatter.format(formatterParse.parse(m.get("lastModifiedDate")));
m is a HashMap and someModifiedDate is coming as 2010-11-26
EDIT: I get InvalidTypeEception. java. Genereated value (java.sql.Date) incompatible with java.lang.String
The snippet below works fine.
Map<String, String> m = new HashMap<String, String>() {{
put("lastModifiedDate", "2010-11-26");
}};
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat formatterParse = new SimpleDateFormat("yyyy-MM-dd");
String s = formatter.format(formatterParse.parse(m.get("lastModifiedDate")));
System.out.println(s);
The output is 11/26/2010
, thus either
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.