Convert from Long to date format

HaOx picture HaOx · Aug 2, 2012 · Viewed 71.6k times · Source

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?

Answer

AAnkit picture AAnkit · Aug 2, 2012

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 this instead 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.