user3068256
user3068256

Reputation: 61

Convert int to date format dd / MM / yyyy in Android

I am developing an application in which I need to get the last sent SMS. All good so I'll know the date of shipment. With the expression int cursor.getColumnIndex indexDate = (DATE) I get an integer but I need to convert a date eses integer format dd / MM / yyyy and then convert that date to String. How I would do?. Thanks in advance.

Upvotes: 2

Views: 7282

Answers (1)

kiwi
kiwi

Reputation: 487

try this:

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

Upvotes: 9

Related Questions