Android 从SMS时间戳格式化时间?

Android 从SMS时间戳格式化时间?,android,cursor,Android,Cursor,我正在使用以下光标查询SMS数据库: Uri uri = Uri.parse("content://mms-sms/conversations?simple=true"); Cursor cursor = _context.getApplicationContext().getContentResolver().query(uri, null, null, null, "normalized_date desc"); 我得到的日期回来,但他们返回的数字格式。现在我知道我可以使

我正在使用以下光标查询SMS数据库:

    Uri uri = Uri.parse("content://mms-sms/conversations?simple=true"); 
    Cursor cursor = _context.getApplicationContext().getContentResolver().query(uri, null, null, null, "normalized_date desc");
我得到的日期回来,但他们返回的数字格式。现在我知道我可以使用以下方法:

SimpleDateFormat dateFormatted = new SimpleDateFormat("hh:mm")

让所有时间以我选择的格式返回,但我想知道是否有更简单的方法来确定时间戳是从今天开始的,还是从一周前开始的?或者另一种更容易确定的方法?

有关相对时间,您可以查看DateUtils.getRelativeTimeSpanString


在2小时前、3天前等情况下,它将具有您想要的输出。

使用SimpleDataFormat格式字符串的任何问题,例如

SimpleDateFormat dateFormatted = new SimpleDateFormat("EEE, MMM d, ''yy")
或者在?

中提供的其他无数选项中,您可以获取日期的日历对象,并评估相对于当前日期获得的范围

    Calendar smsCalendar = Calendar.getInstance();
    smsCalendar.setTimeInMillis( smsTime );  
    year1=c.get(c.YEAR);
    week1=c.get(c.WEEK_OF_YEAR);

    Calendar lastWeek=Calendar.getInstance();       
    year2=c.get(c.YEAR);
    week2=c.get(c.WEEK_OF_YEAR);

    if(year1 == year2){
           if(week1 == week2}{
             //Do what you want here

           }
        }
    }