Showing correct sunrise/sunset times using unix timestamp

后端 未结 2 1728
不知归路
不知归路 2020-12-07 05:46

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 th

2条回答
  •  粉色の甜心
    2020-12-07 06:46

    it sounds like the api is returning different time zones depending on what city you request data

    So taking that into consideration, when converting the timestamp to a datetime object, you need to do something like this:

    import java.time.*
    
    val dt = Instant.ofEpochSecond(/*put time value here*/)
                    .atZone(/*put time zone here*/)
                    .toLocalDateTime() //this will convert it to your system's date time
    

提交回复
热议问题