kotlin - 如何检查当前时间是在kotlin中的某个时间之后还是之前
问题描述
我正在尝试检查当前时间(小时和分钟)是否在某个时间之后或之前,我该如何在 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
}
推荐阅读
- reactjs - 什么样的身份验证流 react-aad-msal 使用
- marklogic - Marklogic Java 客户端 API 标准不起作用
- .net - .net 核心网络 API。当只需要设置最后一个参数时,我的路由应该如何允许可选参数
- python - 查找多个数字列的最大值和最小值并返回具有相应行值的数据框
- emacs - Emacs config 使用不同的操作系统不断将设置从 '(apostrophe) 更改为 (quote) 和向后
- python - 数据分类和清理
- java - 如何调用从不同类传递的数据?
- python - 寻找组合问题的有效算法
- c++ - 当 main.qml 通过 HTTP 导入时,main.cpp 中的“engine.rootObjects().first()”崩溃
- html - 在输入字段上禁用浏览器自动填充(所有浏览器)