我用这个代码:
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);
..和它的工作原理,但给人日期格式“1352933381889”
如何转换成普通的日期/时间格式的字符串类型?
试试这个:
Date date = new Date(cursor1.getLong(0));
String formattedDate = new SimpleDateFormat("MM/dd/yyyy").format(date);
看来您收到以毫秒为单位的日期。 以毫秒转换为Date对象:
long milliSeconds = cursor1.getString(0);
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
String finalDateString = formatter.format(calendar.getTime());