我正在开发一个应用程序,我需要获取最后发送的短信.一切都好,所以我会知道发货日期.使用表达式int cursor.getColumnIndex indexDate =(DATE)我得到一个整数,但我需要转换一个日期,使用整数格式dd/MM/yyyy,然后将该日期转换为String.我该怎么办?提前致谢.
试试这个:
int dateColumn = cursor.getColumnIndex("date"); //integer represent date you get from db
Date d = new Date(Long.parseLong(cursor.getString(dateColumn)));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd " + "\n" + "hh:mm:ss");
String date = dateFormat.format(d); // formatted date in string
Run Code Online (Sandbox Code Playgroud)