android - 使用 SimpleDateFormat 转换 Sqlite 列日期格式

标签 android sqlite

我有一个 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/

相关文章:

android - 在 Android 上将视频设置为墙纸

android - Android内部版本号

android - 如何在数据库中存储格式化文本

android - sqlite-android : how to compare string and get id of that String from database?

android - 类型不匹配。必需的 map <String, Any> 找到的 map <String, Any?>

java - 所有java对象都保存在内存中直到以某种方式被销毁吗?

android - Firestore 数据库 : Updating missing documents

mysql - 安装 MySQL 驱动程序后,Perl SQLite 驱动程序停止工作

vba - SQLite UDF - VBA 回调

android - 如何在Android中制作可变长度的声音