// Playtime.kt (c) Kari Laitinen // http://www.naturalprogramming.com // 2023-01-12 File created. // WARNING! It may be better not to run this program // for a long time on your computer because the infinite // loop of the program consumes quite a lot of processing // power, and that may result in that the electronics // of your computer gets too hot. In my computer the cooling // fan of the processor starts operating immediately when // I start executing this program. import java.util.* class ThreadToDisplayTicksAndTime : Thread() { var must_display_ticks_and_time = true fun stop_this_thread() { must_display_ticks_and_time = false } override fun run() { var previous_time_ticks : Long var current_time_ticks : Long var loop_counter = 0L print( "\n loop_counter current_time_ticks Readable time \n" ) previous_time_ticks = System.currentTimeMillis() while ( must_display_ticks_and_time == true ) { loop_counter ++ current_time_ticks = System.currentTimeMillis() if ( ( current_time_ticks - previous_time_ticks ) > 5000 && ( ( current_time_ticks / 1000 ) % 5 ) == 0L ) { print( "\n " + loop_counter + " " + current_time_ticks + " " ) print( String.format( "%tc", current_time_ticks ) ) previous_time_ticks = current_time_ticks loop_counter = 0 } } } } fun main() { val thread_to_display_ticks_and_time = ThreadToDisplayTicksAndTime() print( "\n Press the Enter key to stop the program.\n" ) thread_to_display_ticks_and_time.start() val any_string_from_keyboard = readLine()!! thread_to_display_ticks_and_time.stop_this_thread() }