I am getting offset time like 180000 from API, but what I need is time zone like newYork/America ,how can I get time zone from offset , is there any method. Any help would be appreciated. I am calculating time from time Epoch like this
fun Int.currentConverter(): String {
val time = SimpleDateFormat("d MMMM, hh:mm a", Locale.ENGLISH)
return time.format(this * 1000L)
}
CodePudding user response:
Can you add timezone in your function and try once
fun Date.currentConverter(): String {
var localFormat="d MMMM, hh:mm a"
val formatter = SimpleDateFormat(localFormat,, Locale.ENGLISH)
formatter.timeZone = TimeZone.getTimeZone("America/New_York")
return formatter.format(this)
}
CodePudding user response:
Try this!
val calendar = Calendar.getInstance(
TimeZone.getTimeZone("GMT"),
Locale.getDefault()
)
val currentLocalTime = calendar.time
val date: DateFormat = SimpleDateFormat("Z")
val localTime: String = date.format(currentLocalTime)