Issue
It might be a stupid question but I'mm trying to do something like, if LocalTime.now
is 9pm, do something. Is there a solution or any leads that might help me?
Solution
You need to check if now is in a range of time close to 9pm. Otherwise, it will only be true if the code happens to be called during the 1 nanosecond that it is exactly 9pm. Something like:
if (LocalTime.now() in LocalTime.of(21, 0)..LocalTime.of(21, 1)) {
//TODO
}
Or you could check if the hour and minute match if you just want to check if we are in the first minute of the hour:
if (LocalTime.now().run { hour == 21 && minute == 0 }) {
//TODO
}
Answered By - Tenfour04
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.