title: Displaying time from timestamp in Unix, UTC in Android Kotlin
body: <p>I am working on a simple weather app and am trying to display time in the format &quot;K:mm a&quot; (eg. 6:30 AM). I am fetching a timestamp in Unix, UTC for the specified place a user searches for such as NYC. The timestamp looks something like 1624836905 and the time zone offset such as -14400. I have a function which adds the two up, converts it to milliseconds and should return the time in the format specified. The function is as follows:</p>
  <pre><code>fun dateTime(time: Int, zone: Int, format: String = &quot;EEE, MMMM d K:mm a&quot;): String {
          return try {
              val sdf = SimpleDateFormat(format)
              val netDate = Date((time.plus(zone)).toLong() * 1000)
              sdf.timeZone = TimeZone.getTimeZone(&quot;UTC&quot;)
              sdf.format(netDate)
          } catch (e: Exception) {
              e.toString()
          }
      }
  </code></pre>
  <p>And I call it such as:</p>
  <pre><code>sunriseTextView.text = dateTime(result2.lookup&lt;Int&gt;(&quot;daily.sunrise&quot;)[0], timeZone, &quot;K:mm a&quot;)
  sunsetTextView.text = dateTime(result2.lookup&lt;Int&gt;(&quot;current.sunset&quot;)[0], timeZone, &quot;K:mm a&quot;)
  </code></pre>
  <p>The expected output is the sunrise/sunset time such as 6:01 AM and 9:05 PM. I am also rendering the current time at the specified place also obtained from the API. As follows:</p>
  <pre><code>dateView.text = dateTime(result2.lookup&lt;Int&gt;(&quot;current.dt&quot;)[0], timeZone)
  </code></pre>
  <p>Which outputs the current date and time at the place in the format &quot;EEE, MMMM d K:mm a&quot; (eg. Mon June 28 8:23 AM).</p>
  <p>The current time is always correct, however, there is a problem with the sunrise and sunset times. If I input NYC, for example, the sunrise is 7:35 PM and sunset 10:39 AM. The sunrise and sunset for Tokyo, on the other hand, appears correct at 4:27 AM and 7:00 PM.</p>
  <p>Clearly I am missing something as I know the API data is correct. I am looking for any suggestions, however, I would appreciate one which does not have API restrictions such as kotlinx-datetime which requires API 26.</p>