Safeer
Safeer

Reputation: 1467

I need to understand the date format returned by cursor in android

What does this date means: 1427856000472? I have got this date from cursor.getString(4). I need the receiving date of the message, but its format is not clear to me. Kindly help, and thank you very much for sharing your knowledge.

Upvotes: 0

Views: 269

Answers (2)

Preethi Rao
Preethi Rao

Reputation: 5175

Its in time in milliseconds .. you need to convert them to proper time.. following thing is what i followed.. it will return date month and year where timestamp is equal to your time .. eg 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; 

Upvotes: 2

Saurav
Saurav

Reputation: 560

That time is the time elapsed since epoch(The Unix epoch is the number of seconds that have elapsed since January 1, 1970).

You can convert epoch time using this link: http://www.epochconverter.com/

You can find the answer here in this post: convert epoch time to date

Hope this helps.

Upvotes: 1

Related Questions