-3

I am fetching date time from my API in which I am facing problem how I can set this date time to textView. I want to show this DateTime in this format how I can do this 9 Sep 2018. here is my snapshot in which date format is given. that format is coming from my API. Date time Format in API snapshot I have uploaded the snapshot of textView

how I can set the review date to text View. Thank you in advance how I can set this to my textView

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
ansar abbas
  • 11
  • 1
  • 8

1 Answers1

0

If you ask a solution

String date = "/Date(1536566908220)/";
String milli = date.replaceAll("[^0-9]", "");
if (!TextUtils.isEmpty(milli)) {
    long time = Long.parseLong(milli);
    SimpleDateFormat df = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
    String formattedDate = df.format(time);
    System.out.println(formattedDate); // 13-4-2015 10:59:26
}

If you ask a suggestion.

This is not a good format to receive date "/Date(778844555)/".

  • either make it totally millisecond like 1536566913832 from backend.
  • or make it a string date format only like 13-4-2015 10:59:26
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • Nice to provide a suggestion for a better format. However for the vast majority of purposes the best format is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), for example `2015-04-13T10:59:26Z` or in case of a date only just `2018-09-09`. – Ole V.V. Sep 11 '18 at 10:20
  • @OleV.V. I just showed an example, you can please edit my answer. – Khemraj Sharma Sep 11 '18 at 10:22