I'm getting a UNIX timestamp from DarkSkyApi for the sunrise & sunset times for the selected location and i want to convert it to a DateTime format and display it to the user. I want the time values to be local.
Example case : The user is in Italy and selects "Tokyo, JP" as the desired location to fetch weather info for. The sunrise & sunset time values should be formatted & shown as local times. So for Tokyo, sunrise should be something around 4:34 AM & 18:36 PM for sunset.
With what i have right now, i'm getting wrong values such as 12:17 for sunrise & 2:29 for sunset. Any ideas on what i'm doing wrong here?
P.S. The tmz
var is the timezone of the selected location , so in this case it would be "Asia/Tokyo". Here's what i'm doing right now for the sunset time (same for the sunrise time):
private fun setViewHolderWeekDaySunsetTime(holder: ViewHolder, sunsetTime: Long, tmz: String) {
val dt = Instant.ofEpochSecond(sunsetTime).atZone(
ZoneId.of(tmz)
)
val formatted = dt.format(DateTimeFormatter.ofPattern("HH:mm"))
holder.weekDaySunsetTime.text = formatted
}
dt
to see – Rajputunix time = 1588930440 sunset time = 1970-01-19T11:22:10.440+02:00[Europe/Athens]
. When i do multiply it i get this :unix time = 1588930440 sunset time = 2020-05-08T12:34+03:00[Europe/Athens]
using this Log statementLog.i("WEEKLYWEATHER","unix time = $sunsetTime sunset time = $dt")
– BracersunsetTime
,tmz
orholder
? – Solution