我有一个Android应用程序,该应用程序使用sqlite数据库并将日期存储在字段名称“match_date” 下,格式为 2014-06-12

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

这是代码块

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

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

最佳答案

我不确定您的意思是:

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

关于android - 如何检索存储在sqlite中的日期并将其转换为timeStamp以便能够将其与当前日期进行比较?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23922482/

10-11 00:45