I am receiving data from an API that returns the following date:
"2020-04-15T12:27:22.000Z"
I'm using this method to format the date:
private fun formatarData(dataAtualizacao: String): String {
var simpleDateFormat = SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
Locale.getDefault()
)
simpleDateFormat.timeZone = TimeZone.getDefault()
val data = simpleDateFormat.parse(dataAtualizacao)
return if (data != null) {
simpleDateFormat = SimpleDateFormat("dd MMM yyyy - HH:mm", Locale.getDefault())
simpleDateFormat.format(data)
} else {
getString(R.string.error)
}
}
The expected result was "15 abr 2020 - 09:27" but I am receiving the result "15 abr 2020 - 12:27".
How to fix this error?