8

私はこのコードを使用しました:

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」で日付を返し
ます文字列型の通常の日付/時刻形式に変換するにはどうすればよいですか?

4

2 に答える 2

16

これを試して:

Date date = new Date(cursor1.getLong(0));
String formattedDate = new SimpleDateFormat("MM/dd/yyyy").format(date);
于 2012-11-15T12:03:17.640 に答える
9

ミリ秒単位で日付を受け取っているようです。ミリ秒を 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());
于 2012-11-15T12:09:38.967 に答える