我需要了解android中游标返回的日期格式



这个日期意味着什么:1427856000472?我从cursor.getString(4)中得到了这个日期。我需要消息的接收日期,但我不清楚它的格式。请提供帮助,并非常感谢您分享您的知识。

以毫秒为单位的时间。。你需要把它们转换成合适的时间。。以下是我所遵循的。。它将返回年月日其中时间戳等于您的时间。。例如1427856000472

    final Calendar cal = Calendar.getInstance();
    java.text.DateFormat df= DateFormat.getMediumDateFormat(mCtx);
    java.text.DateFormat df1=DateFormat.getTimeFormat(mCtx);  
    String date = (df.format(timeStamp).toString());
    String  time=df1.format(timeStamp);
    cal.setTimeInMillis(timeStamp);
    int messageYear=cal.get(Calendar.YEAR);
    int month=cal.get(Calendar.MONTH);
    int dates=cal.get(Calendar.DATE);
    Locale locale=Locale.getDefault();
    String monthName=cal.getDisplayName(Calendar.MONTH, Calendar.SHORT , locale);
    String date =  monthName+" "+dates+"n"+time; 

该时间是自epoch以来经过的时间(Unix epoch是自1970年1月1日以来经过的秒数)。

您可以使用此链接转换epoch时间:http://www.epochconverter.com/

你可以在这篇文章中找到答案:将历元时间转换为日期

希望这能有所帮助。

最新更新