DateFormat#format接受日期,而不是字符串。
用
String sCertDate = dateFormat.format(new Date());
如果您有来自数据库的特定格式的字符串,并且想要转换为日期,则应使用parse方法。
@Sonesh-
假设您在数据库中有一个字符串,恰好代表一个Date(将对象存储在数据库中作为日期会更好吗?),然后将其首先设置
parse为所需的格式,然后将
format其设置为您想要的字符串格式。
// Assumes your date is stored in db with format 08/01/2011SimpleDateFormat dateFormatOfStringInDB = new SimpleDateFormat("MM/dd/yyyy");Date d1 = dateFormatOfStringInDB.parse(yourDBString);SimpleDateFormat dateFormatYouWant = new SimpleDateFormat("MMMMM dd, yyyy");String sCertDate = dateFormatYouWant.format(d1);


