如何检索存储在sqlite中的日期并将其转换为timeStamp以便能够将其与当前日期进行比较?

时间:2014-05-28 21:51:08

标签: android date error-handling android-sqlite

我有一个Android应用程序,使用sqlite数据库并在字段名称&#34; match_date&#34; 下以 2014-06-12 。< / p>

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

这是代码块

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;
    }

希望有人能帮助我,我会很感激这一帮助。

1 个答案:

答案 0 :(得分:0)

我不确定你的意思是:

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