I have to convert particular Timestamp value to Time. I can convert it to 24 hour format successfully. But getting minor issue in displaying or converting it to 12 hour format.
For the Timestamp : 1639588870 I am getting,
24 Hour format : 22:51 (correct)
12 Hour format : 22:51 PM (incorrect)
The 12 Hour format should be 10:51 PM instead of 22:51 PM
I am using below function to convert Timestamp value to my specific Time format display value :
fun getDateTime(timeStamp: String): String? {
var sdf = SimpleDateFormat("HH:mm")
try {
if (prefManager.getDefaultTimeSelection().equals(TIME_24_HOUR)) {
sdf = SimpleDateFormat("HH:mm")
} else {
sdf = SimpleDateFormat("HH:mm aa")
}
val netDate = Date(timeStamp.toLong() * 1000)
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
}
}
What might be the issue in converting Timestamp to 12 Hour format ?
Thanks.