【问题标题】:how to retrieve date stored in the sqlite and converte it to timeStamp to be able to compare it with the current date?如何检索存储在 sqlite 中的日期并将其转换为 timeStamp 以便能够将其与当前日期进行比较?
【发布时间】:2014-05-28 21:51:07
【问题描述】:

我有一个使用 sqlite 数据库并以这种格式 2014-06-12 在字段名称 "match_date" 下存储日期的 Android 应用程序。

我想要的是检索存储的日期,然后将其转换为时间戳以便能够将其与当前日期进行比较。

这是代码块

public Cursor getAllRows(PendingIntent notificationIntent) throws ParseException {
        String where = null;

        c = database.query(true, TABLE_NAME, ALL_KEYS, where, null, null, null,
                null, null);
        if (c != null) {

            c.moveToFirst();

            // test for get current date and convert it to timeStamp 



            Log.e("time test","the current date in timeStamp =" + d1.getTime());



             int index = c.getColumnIndex("match_date");


             Date dateInGetAllRow = (Date)format.parse(c.getString(c.getColumnIndex("match_date")));


            Log.e("inside the getAllRows", "first day is " + dateInGetAllRow.getTime());



            Log.e("inside the Shownotification", "index is" + index);


            ///////////////////////////////////////////////////////////////////


            while (!c.isAfterLast()) {
                listdetail = new ItemDetails();

                listdetail.setTeam1(c.getString(c.getColumnIndex("team1")));

                listdetail.setTeam2(c.getString(c.getColumnIndex("team2")));

                listdetail.setDate_match(c.getString(c
                        .getColumnIndex("match_date")));








                    NotificationCompat.Builder builder = new Builder(
                            getApplicationContext());
                    Notification notification = builder
                            .setSmallIcon(R.drawable.fifa_2014_4)
                            .setContentTitle("Up Comming Match")
                            .setContentText(
                                    c.getString(c.getColumnIndex("match_date"))
                                            + (c.getColumnIndex("team1"))
                                            + (c.getColumnIndex("team2"))).build();


                    displayNotification(notification);




                c.moveToNext();
        }


      }
        return c;
    }

希望有人可以帮助我,我将不胜感激。

【问题讨论】:

    标签: android date error-handling android-sqlite


    【解决方案1】:

    我不确定你是不是这个意思:

    java.util.Date date= new java.util.Date();
    Timestamp ts = Timestamp(date.getTime());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      • 2015-12-05
      相关资源
      最近更新 更多