0

I have date strings in a given matching format: 2017-03-25T11:24:20 or 2020-06-26T11:14:00

and would like to find which day of the week is on a given date, usin java or Kotlin

U wan
  • 11
  • 1
    Does this answer your question? [Java format yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss](https://stackoverflow.com/questions/15730298/java-format-yyyy-mm-ddthhmmss-sssz-to-yyyy-mm-dd-hhmmss) – Emre Uygun Feb 27 '22 at 11:31

1 Answers1

1

You can parse the datetime string to LocalDateTime object and use its getDayOfWeek() method (doc) to find the day of week, which returns a DayOfWeek enum (doc). In Kotlin, it would look like

val date = LocalDateTime.parse("2017-03-25T11:24:20")
println(date.dayOfWeek) // would print "SATURDAY"

On the DayOfWeek enum, you could use getDisplayName(TextStyle style, Locale locale) to get a localized textual representation, such as 'Mon' or 'Friday', or getValue() to get the day-of-week int value.

Madhu Bhat
  • 13,559
  • 2
  • 38
  • 54