how to get date from milliseconds in android

Saqib Abbasi picture Saqib Abbasi · Dec 2, 2012 · Viewed 24.1k times · Source

I have time in milliseconds, now I want to separate time and date from these milliseconds.

how can i do this???

Answer

Mohsin Naeem picture Mohsin Naeem · Dec 2, 2012

you can use like this

Calendar cl = Calendar.getInstance();
cl.setTimeInMillis(milliseconds);  //here your time in miliseconds
String date = "" + cl.get(Calendar.DAY_OF_MONTH) + ":" + cl.get(Calendar.MONTH) + ":" + cl.get(Calendar.YEAR);
String time = "" + cl.get(Calendar.HOUR_OF_DAY) + ":" + cl.get(Calendar.MINUTE) + ":" + cl.get(Calendar.SECOND);