How to convert date format from Android inbox sms

user1824542 picture user1824542 · Nov 15, 2012 · Viewed 11.4k times · Source

I used this code:

String[] columnDate =   new String[] {"date"};
Cursor cursor1 = getContentResolver().query(Uri.parse("content://sms/inbox"),
    columnDate ,null, null, "date desc limit 1");
cursor1.moveToPosition(0);
String msgData1Date = cursor1.getString(0);

..and it works but gives date on this format "1352933381889"
How to convert to normal date/time format in String type?

Answer

Flávio Faria picture Flávio Faria · Nov 15, 2012

Try this:

Date date = new Date(cursor1.getLong(0));
String formattedDate = new SimpleDateFormat("MM/dd/yyyy").format(date);