Kotlin Android / Java String DateTime Format, API21

前端 未结 3 1277
死守一世寂寞
死守一世寂寞 2020-12-15 05:46

I want convert string datetime to formatted string. e.g \"2018-12-14T09:55:00\" to \"14.12.2018 09:55\" as String => Textview.text

how can I do this with kotlin or

3条回答
  •  Happy的楠姐
    2020-12-15 06:23

    If you have a date-time that represents a value in a specific time zone but the zone is not encoded in the date-time string itself (eg, "2020-01-29T09:14:32.000Z") and you need to display this in the time zone you have (eg, CDT)

    val parsed = ZonedDateTime.parse("2020-01-29T09:14:32.000Z", DateTimeFormatter.ISO_DATE_TIME).withZoneSameInstant(ZoneId.of("CDT"))
    

    That parsed ZoneDateTime will reflect the time zone given. For example, this date would be something like 28 Jan 2020 at 8:32am.

提交回复
热议问题