在Android中将int转换为日期格式dd/MM/yyyy

use*_*256 1 android date

我正在开发一个应用程序,我需要获取最后发送的短信.一切都好,所以我会知道发货日期.使用表达式int cursor.getColumnIndex indexDate =(DATE)我得到一个整数,但我需要转换一个日期,使用整数格式dd/MM/yyyy,然后将该日期转换为String.我该怎么办?提前致谢.

kiw*_*iwi 8

试试这个:

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)

  • 也许你可以选择这个作为正确答案:) (6认同)