我使用下面的代码把数据保存到 SQlite 数据库中( java.sql.Date)
public String dateToDB ( Date date)
{
String convertedDate = date.toString(); // yyyy-mm-dd
return convertedDate;
}
如何从SQlite中检索字符串,把已复原的字符串转换成sql date 类型?
private Date dateFromColumn(String columName, Cursor result)
{
// ???????
return date
}
String string = result.getString(result.getColumnIndex(columName))
Date.parse(string); //可以得到Date
//下面的可以格式化日期
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd") ;
String s = format.format(Date.parse(string)) ;
我找到的相关资料:
Date.valueOf(String dateString) creates a Date from a string representation of a date in SQL format: yyyy-MM-dd
是这个意思吗?
private Date dateFromColumn(String columName, Cursor result)
{
String strDate = c.getColumnIndex("yourcolumnindex...")
return Date.valueOf(strDate);
}