I want to create a countdown class, which will countdown to a later, desired date(using only hours, seconds, and minutes, other stuff not important) from now. In a GUI I want to show the user the remaining time, updating every second with a Timer.
The problem is: if the user chooses a date late enough, for example: 23 hours 59 minutes 59 seconds till the countdown ends, that means I have to call LocalDateTime.now()
more than 80000 times.
I read LocalDateTime
is immutable, so I expect my actualDate = LocalDateTime.now()
will leave a tons of unused objects back to the GC, which is sloppy. Is there a way around this with using only LocalDateTime
?