UTC string to UTC date conversion in android
fun convertStringDateToDate(stDate: String, format: String, tzCode: String? = null): Date? {
return try {
val inputFormat = SimpleDateFormat(format)
inputFormat.timeZone = TimeZone.getTimeZone("UTC")
return inputFormat.parse(stDate)
} catch (e: Exception) {
e.printStackTrace()
null
}
}
above function parses the date string in the local timezone of the device! Any idea how to get the UTC date
it gives as output of "Fri Dec 31 10:01:24 GMT+05:30 2021"
for input string of "2021-12-31T10:01:24Z"