androiddatekotlindate-formattingcurrent-time

Display local date in textview (Kotlin)


I'm trying to display the local date (ie Tuesday, September 14, 2021) in a textview and I'm having a hard time finding a way to do it. Any tips or ideas?


Solution

  • You can use SimpleDateFormat class to format dates. To acheive the format you specified in question, use this:

    textView.text = SimpleDateFormat("EEEE, MMMM dd, yyyy").format(Date())
    

    To understand the meaning of different date and time patterns, checkout this link.