【发布时间】:2013-01-09 15:52:44
【问题描述】:
我有一个以 yyyy-mm-dd 格式将日期作为字符串的 sqlite 列,我正在尝试使用 SimpleDateFormat 对其进行转换,但总是返回 01-01-1970? 这是我的适配器的代码:
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.swimm_date)
{
int DateUSA = cursor.getInt(columnIndex);
TextView tv = (TextView)view;
DateFormat FormatDate = new SimpleDateFormat ("dd-MM-yyyy");
String DateEUR = FormatDate.format(DateUSA);
tv.setText(DateEUR);
return true;
}
【问题讨论】:
-
int DateUSA = cursor.getInt(columnIndex);如果您将其存储为字符串..为什么要将其检索为 int..
-
yyyy-MM-dd或dd-MM-yyyy? -
在数据库中我有字符串 yyyy-MM-dd 我想在 dd-MM-yyyy 中转换