Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get date from milliseconds in android

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

how can i do this???

like image 863
Saqib Abbasi Avatar asked Dec 02 '12 09:12

Saqib Abbasi


2 Answers

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);
like image 77
Mohsin Naeem Avatar answered Oct 04 '22 17:10

Mohsin Naeem


This function will give you a String date from milliseconds

public static String getFormattedDateFromTimestamp(long timestampInMilliSeconds)
{
    Date date = new Date(); 
    date.setTime(timestampInMilliSeconds);
    String formattedDate=new SimpleDateFormat("MMM d, yyyy").format(date);
    return formattedDate;

}
like image 34
Kiran Kumar Avatar answered Oct 04 '22 16:10

Kiran Kumar