I have a time string formatted in Zulu time of "2022-11-21T16:29:28.325Z" and then parsing it for a formatted string in a destination timezone.
try {
val readLocalDateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'")
readLocalDateFormat.timeZone = TimeZone.getTimeZone("UTC")
val writeLocalDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm")
writeLocalDateFormat.timeZone = TimeZone.getTimeZone(timeZone)
return writeLocalDateFormat.format(readLocalDateFormat.parse(dateStr))
} catch (e: Exception) {
Log.e(TAG, "Failed to parse date: " + dateStr)
return dateStr
}
In the case, the destination timezone is "America/Halifax" so I would expect the output string to be "2022-11-21 12:29" since Halifax is 4 hours behind UTC time but instead the output is "2022-11-21 12:34" with an additional 5 minutes added to the time. I can't figure out why this 5 minutes is being added. Any ideas?