import "time" func main() { startTime := time.Now() time.Sleep(2 * time.Second) endTime := time.Now() elapsedTime := endTime.Sub(startTime) fmt.Println(elapsedTime) }
import ( "time" "fmt" ) func main() { t1 := time.Date(2022, time.December, 1, 0, 0, 0, 0, time.UTC) t2 := time.Date(2022, time.December, 25, 0, 0, 0, 0, time.UTC) duration := t2.Sub(t1) days := int(duration.Hours() / 24) fmt.Printf("There are %d days until Christmas\n", days) }This code calculates the number of days between December 1st and December 25th in the year 2022. The output should be "There are 24 days until Christmas". Package library: time.