0

I want to parse this value "AuthDate": "2021-08-17T19:03:27+04:00" like 17/08/21, 19:03:27

I tried this var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd, HH:MM:SS") but its not working

3
  • Have you parsed it correctly and only pending to display the final format? Commented Aug 17, 2021 at 15:19
  • yeah, Im parsing "AuthDate" value , saving it in variable and than tried to convert with formatter Commented Aug 17, 2021 at 15:22
  • let me know if the answer below is what you needed, accept it if you think it's correct 🙂 Commented Aug 17, 2021 at 15:27

1 Answer 1

1

Firstly, you would need to parse the string that you've got into an object that kotlin can use, and then, you can use that object to format it to whichever format suits you :

fun main() {
    val string = "2021-08-17T19:03:27+04:00"
    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssz")
    val parsedDate = formatter.parse(string)
    val displayFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd, HH:MM:SS")
    val result = displayFormatter.format(parsedDate)
    println(result)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.