例1:String dateStr = "2000-12-11 06:23:12";
Date date = new Date() ;
SimpleDateFormat strToDate = new SimpleDateFormat ("yyyy-MM-dd-hh:mm:ss");
// parse format String to date
date = strToDate.parse(dateStr);
System.out.println(date);
// date convert to format String according the format String
SimpleDateFormat dateToStr = new SimpleDateFormat ("dd/MM/yyyy-hh:mm:ss");
// parse date to format String
String temp = dateToStr.format(date);
System.out.println(temp);
Example two:
/**
* Get Date
* @param dateStr
* @return
*/
String dateStr = "Thu Aug 05 12:56:00 CST 2010";
private Date getExaminationDate(String dateStr) {
Date date = new Date() ;
try {
date = new SimpleDateFormat().parse(examinationDate);
} catch (ParseException e) {
e.printStackTrace ();
}
return date;
}
Transfer from http://www.jinflex.com/index.php/archives/86