2
我從我的SQLite
數據庫檢索了一個毫秒String
,並且想要將其轉換爲格式化日期String
。它基本上工作,但不是當我在數組中嘗試它(見下文)。它拋出一個NumberFormatException
。我怎樣才能解決這個問題?將毫秒字符串轉換爲格式化日期SimpleCursorAdapter中的字符串
adapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor,
new String[] { getDate(Long.parseLong(Database.KEY_DATE), "dd. MMMM yyyy hh:mm:ss") , Database.KEY_NAME },
new int[] {R.id.text1, R.id.text2}, 0);
public static String getDate(Long milliSeconds, String dateFormat){
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}
@Sam你在嗎? – user1617102
什麼是'Database.KEY_DATE'?我懷疑問題是當你試圖解析它時,儘管所有日曆的東西都是編寫'新日期(毫秒)'的一種很長的方式' –
Database.KEY_DATE檢索一個毫秒的字符串。 – user1617102