-4

I am working on some error like i am getting response of a date which is like 1510808400000 and i have to display this as a valid date format like dd-mm-yy Suggest me is there any way to convert that long value to valid date format. or guide me possible changes.

2 Answers2

1

Use below code

long millis = Long.parse("1510808400000 ");
Date date = new Date(millis);
String displayDate = new SimpleDateFormat("dd-mm-yy").format(date);
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
1

modify date format as required.

  private String getDate(long timeStamp){

        try{
            SimpleDateFormat sdf = new SimpleDateFormat("MM dd, yyyy");
            Date netDate = (new Date(timeStamp));
            return sdf.format(netDate);
        }
        catch(Exception ex){
           ex.printStackTrace();
            return null;
        }
    }
Aks4125
  • 4,522
  • 4
  • 32
  • 48