1

I'm receiving this Timestamp string from the server:

"timestamp": "2021-02-21T22:15:37.672+00:00" I'm not sure what format it's in

how I can format it to a Month day time format such as February 21st, 4:00pm?

Edit:

Using the answer below:

String time = "2021-02-21T22:15:37.672+00:00";
try {
  Date dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").parse(time);
  Log.d(TAG, "onCreate: " + dateFormat.toString());
} catch (ParseException e) {
  e.printStackTrace();
}
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
  • Does this answer your question? https://stackoverflow.com/questions/12487125/java-how-do-you-convert-a-utc-timestamp-to-local-time – Tobi Feb 22 '21 at 01:30
  • 1
    If this is in android, you should probably be using DateFormat instead as that is the android standard for dealing with date. Especially when it comes to detecting locale appropriately and when the format changes. – JoxTraex Feb 24 '21 at 02:10

2 Answers2

2

That most likely is UTC time. You can tell it is because it doesn't have an offset via the +00:00, which is used for timezone offset. UTC can be converted to other timeszones using DateFormat. Ref:

https://developer.android.com/reference/java/text/DateFormat

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
2

"2021-02-21T22:15:37.672+00:00" is "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" in SimpleDateFormat in JAVA SE7.

"February 21st, 4:00pm" is "MMM dd, h:mma"
The "st" part seems like it have to be determine manually in SimpleDateFormat.

SimpleDateFormat

ming chen
  • 550
  • 4
  • 13