Static, not dynamic
Can someone tell me why it’s not updating ?
A LocalTime
represents a particular time of day. The object is immutable, unchanging, and cannot be updated.
Calling LocalTime.now()
captures the time of day at that moment of execution. The value will not change later. To get the current time of day later, call LocalTime.now()
again for a fresh new object.
To display the value of a LocalTime
object, call .toString
to generate text in standard ISO 8701 value. For other formats, use DateTimeFormatter
. Search to learn more as this has been handled many times already.
Elapsed time
And how can I get time running with a LocalTime object from a user input ?
Perhaps you mean you want to determine the amount of time that has elapsed since an earlier moment, such as when the user last performed a particular act or gesture.
so I can see time passing
For elapsed time, you need to track a moment rather than a time-of-day. The Instant
class represents a moment in UTC.
Instant instant = Instant.now() ; // Capture the current moment in UTC.
Calculate elapsed time on a scale of hours-minutes-seconds with a Duration
.
Duration d = Duration.between( instant , Instant.now() ) ;
9
solved Update a Localtime object from LocalTime.of() method on the java console [closed]