I am receiving from my clients a String like these in this format
yyyy-MM-dd'T'HH:mm:ss.SSSXXX:
2021-02-04T15:31:22.265-05:00
2021-02-04T15:31:22.265+00:00
2021-02-04T15:31:22.265-06:00
and i need to convert them to a new format:
MMMM dd, yyyy - HH:mm a z (where z is the three character abbreviation for the timezone. Ex. EST)
February 02, 2021 - 15:31 PM EST
February 02, 2021 - 15:31 PM UTC
February 02, 2021 - 15:31 PM CST
Normally i would do something like:
SimpleDateFormat inDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
SimpleDateFormat outDateFormat = new SimpleDateFormat("MMMM dd, yyyy - HH:mm a z")
Date date = inDateFormat.parse("2021-02-04T15:31:22.265-05:00");
String convertedTime = outDateFormat.format(date) // February 02, 2021 - 15:31 PM EST
But i then realized that it was only printing EST because thats where I am. But if a user were to be in another timezone and use this it would become their time but EST would still be on the end. Such as if they send 2021-02-04T15:31:22.265+00:00 then it would return February 02, 2021 - 15:31 PM EST which is 5 hours in the past for them.
So how can i take a string that includes the offset and simply turn it into a string in a different format from the same offset? I would expect the outcome of someone from UTC sending 2021-02-04T15:31:22.265+00:00 to be February 02, 2021 - 15:31 PM UTC