0

我是android新手,我已经开发了一个应用程序,现在我想申请每月订阅,我必须跟踪日期,我已经尝试了以下代码

try {
            before = (Date)formatter.parse(date);


        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Date now = new Date();

        long diff = now.getTimeInMillis() - before.getTimeInMillis();
        long days = diff / ONE_DAY;
        if(days > 30) { // More than 30 days?
             // Expired !!!
        }

它在 long diff = now.getTimeInMillis() - before.getTimeInMillis() 处给出错误;

那么你能告诉我这个的替代方法是什么吗?

4

1 回答 1

0

您可以从日历中获取日期:

Calendar c = Calendar.getInstance(); 
int seconds = c.get(Calendar.SECOND);

您可以从中获得许多其他常量Calendar

检查Calendar文档

于 2013-10-24T08:17:27.510 回答