我想检查当前时间(小时和分钟)是在某个时间之前还是之后,我该如何在 kotlin 中做到这一点
最佳答案
您可以使用 Calendar
类:
val currentTime = Calendar.getInstance()
val timeToMatch = Calendar.getInstance()
timeToMatch[Calendar.HOUR_OF_DAY] = hourToMatch
timeToMatch[Calendar.MINUTE] = minuteToMatch
when {
currentTime == timeToMatch -> // the times are equals
currentTime < timeToMatch -> // currentTime is before timeToMatch
currentTime > timeToMatch -> // currentTime is after timeToMatch
}
关于kotlin - 如何检查当前时间是在kotlin中的某个时间之前还是之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60096853/