package main

import ( "fmt" "time" )

func main() { go runClock() go runStopwatch() go runTimer()

var input string
fmt.Scanln(&input)

}

func runClock() { for { currentTime := time.Now() clock := currentTime.Format("15:04:05") fmt.Println("Clock:", clock) time.Sleep(time.Second) } }

func runStopwatch() { var input string for { fmt.Println("Press Enter to start stopwatch") fmt.Scanln(&input)

	startTime := time.Now()

	fmt.Println("Stopwatch started")

	fmt.Println("Press Enter to stop stopwatch")
	fmt.Scanln(&input)

	endTime := time.Now()

	elapsedTime := endTime.Sub(startTime)
	fmt.Println("Stopwatch stopped")
	fmt.Println("Elapsed Time:", elapsedTime)
}

}

func runTimer() { var duration int for { fmt.Println("Enter duration in seconds:") fmt.Scanln(&duration)

	fmt.Println("Timer started")

	timer := time.NewTimer(time.Duration(duration) * time.Second)

	<-timer.C

	fmt.Println("Timer expired")
}
丰富下面的代码package mainimport 	fmt	timefunc main 	go runClock	go runStopwatch	go runTimer	var input string	fmtScanln&inputfunc runClock 	for 		currentTime = timeNow		clock = currentTimeFormat150405		fmtPr

原文地址: https://www.cveoy.top/t/topic/hIin 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录