fun getFormatFromISO(iso: String, pattern: String): String {
var res: String? = ""
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH)
formatter.timeZone= TimeZone.getTimeZone("UTC")
return try {
val date = formatter.parse(iso)
val timeFormat = SimpleDateFormat(pattern, Locale.getDefault())
timeFormat.timeZone= TimeZone.getDefault() // to convert to devices timezone
res=timeFormat.format(date)
res
} catch (var6: ParseException) {
"ERR"
}
}
I am trying to change the Api's response variable to current device's timestamp so that it will be used as some "textview.text". The part where "TimeZone.getDefault()" is used, it is suppose to change the UTC time-zone to device's time zone.But it is not changing, instead it is parsing UTC converted time.
Passing "H", "mm" in the parameter 'pattern', passing something like "2021-10-26T07:22:37Z" in the parameter'iso'
the result is :
date val is 'Tue Oct 26 06:27:18 EDT' res is 06 || res is 27
Required result is res value to be in Device's Time Zone.