>我使用了以下代码:
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.getLong(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());