how to convert UTC date to locale GMT time on android

后端 未结 5 779
轻奢々
轻奢々 2021-01-05 04:53

I have this date string : 2016-04-26T09:14:10.477Z which is in UTC timezone. I want to convert it to the user local Timezone, so if it is GMT +02:00, I want a d

5条回答
  •  梦毁少年i
    2021-01-05 05:19

    The question was in Kotlin and I see all the answers are written in Java, so here is the Kotlin solution

    val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ", Locale.getDefault())
    formatter.timeZone = TimeZone.getTimeZone("UTC")
    val result = formatter.parse(dateAsString)
    

提交回复
热议问题