HaOx HaOx - 7 months ago 28
Android Question

Convert from Long to date format

I want to convert Long value to String or Date in this format dd/mm/YYYY.

I have this value in Long format: 1343805819061.

It is possible to convert it to Date format?



You can use below line of code to do this. Here timeInMilliSecond is long value.

 String dateString = new SimpleDateFormat("MM/dd/yyyy").format(new Date(TimeinMilliSeccond));

Or you can use below code too also.

 String longV = "1343805819061";
 long millisecond = Long.parseLong(longV);

// or you already have long value of date, use that oinstead of milliseconds variable. String dateString= DateFormat.format("MM/dd/yyyy", new Date(millisecond)).toString();

Reference:- DateFormat and SimpleDateFormat

P.S. Change date format according to your need