Home > other >  how to change greeting textView i.e, Good morning or Good night in Android studio using Kotlin
how to change greeting textView i.e, Good morning or Good night in Android studio using Kotlin

Time:11-23

Here is the screenshot of my app

I am making an app in kotlin language. I want to change that Good morning textview to good evening when time is between 4 pm to 8pm and goodnight when time is in range of night time and agin to good morning when time pasts 12 am.

how can i do it in kotlin?

CodePudding user response:

Simply get hour like this:

val currentHour = Calendar.getInstance().get(Calendar.HOUR)

And set text, based on the hour.

text.text = if(currentHour > 20 && currentHour < 4) "Good evening" else "Good morning"
  • Related