Home > Blockchain >  how to sort date today onwards in kotlin
how to sort date today onwards in kotlin

Time:11-25

2021-05-31T22:59:59Z
2022-05-11T22:59:59Z
2022-06-21T22:59:59Z
2022-05-28T22:59:59Z
2022-06-31T22:59:59Z
2022-11-30T23:59:59Z

how to sort date based on today date suppose today date is 2021-11-25T21:59:59Z then our date should be sort like this

    2022-05-11T22:59:59Z
    2022-05-28T22:59:59Z
    2022-06-21T22:59:59Z
    2022-06-31T22:59:59Z
    2022-11-30T23:59:59Z
    2021-05-31T22:59:59Z

dates.sortedByDescending {
            (it.toFormattedFullDateFullTime).millis.toInt() >  currentDateTimeUTC.millis.toInt()

}

but i am unable to to this please help me how to sort date based on current date .

CodePudding user response:

Try with below

 val result = dates.sortedByDescending {
        LocalDate.parse(it, ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault()))
    }

    println(result)
  • Related