如何日期格式从Android的收件箱中的短信转换(How to convert date forma

2019-07-03 20:23发布

我用这个代码:

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”
如何转换成普通的日期/时间格式的字符串类型?

Answer 1:

试试这个:

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


Answer 2:

看来您收到以毫秒为单位的日期。 以毫秒转换为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());


文章来源: How to convert date format from Android inbox sms