Given these two date Strings, I am trying to create a menu that allows you to select from the two dates (these are returned from an API with the users timezone):
2019-12-20T00:00:00.000-05:00
2019-12-19T00:00:00.000-05:00
I use the following code to parse the date string in the users preferred timezone (I have downloaded this locally to their devices). I have verified that the TZUtils.getUsersTimeZone() returns this timezone: America/New York
which has an offset of -5.
fun getDateForString(date: String): Date {
val parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
parser.timeZone = TZUtils.getUsersTimeZone()
return parser.parse(date)
}
When these dates are parsed, they are parsed into my local time time (offset -6) and not in the users local time zone (-5), even though I specify to use the users local time zone. When I create the popup menu, I used the following code to show the dates
public String getStringForDate(Date date) {
DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
return dateFormat.format(date);
}
And this returns me the wrong dates to select from (the dates are based on my timezone and not the users). Furthermore, when I select the data from the menu, the function I use to filter data based on if it is the same day as the selected date doesn't work because it uses my timezone as well. How do I fix this or do I just "assume" this will work for users since their devices are in their timezones?