How to convert date format from Android inbox sms

风流意气都作罢 提交于 2019-12-01 15:02:07

问题


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?


回答1:


Try this:

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



回答2:


It seems that you are receiving the date in miliseconds. To convert miliseconds into a Date object:

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());


来源:https://stackoverflow.com/questions/13397149/how-to-convert-date-format-from-android-inbox-sms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!