我有一个 sqlite 列,其中日期作为 yyyy-mm-dd 格式的字符串,我正在尝试使用 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;
}
最佳答案
也许这个代码 fragment 可以帮助您:
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.swimm_date) {
DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
TextView tv = (TextView)view;
tv.setText(sdf.format(java.util.Date.parse(cursor.getString(columnIndex))));
return true;
}
关于android - 使用 SimpleDateFormat 转换 Sqlite 列日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14241068/