10 examples of 'golang print time' in Go

Every line of 'golang print time' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
216func print_perf(name string, time float64) {
217 fmt.Printf("go,%v,%v\n", name, time*1000)
218}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

28func timed(name string) func() {
29 if len(name) > 0 {
30 fmt.Printf("%s... ", name)
31 }
32 start := time.Now()
33 return func() {
34 fmt.Println(time.Since(start))
35 }
36}
6func main() {
7 // Create new date.
8 a := time.Date(2018, 4, 11, 0, 0, 0, 0, time.UTC)
9
10 delta := time.Now().Sub(a)
11 fmt.Println(delta.Hours())
12
13 duration := time.Since(a)
14 fmt.Println(duration.Hours())
15}
22func main() {
23 fmt.Print("APP-STARTED!\n")
24 for {
25 fmt.Printf("%s\n", time.Now().Format("Mon Jan 2 15:04:05 -0700 MST 2006"))
26 }
27}
112func printTimestamp(id ksuid.KSUID) {
113 fmt.Println(id.Timestamp())
114}
10func main() {
11 b = make(map[string]float64)
12 beginTime := time.Now()
13 fmt.Println(binomal(100, 50, 0.5))
14 fmt.Println("耗时", time.Since(beginTime))
15}
37func main() {
38 starttime := time.Now()
39
40 answer := 0
41 for n := 50; ways(n, 50) < 1000000; n++ {
42 answer = n + 1
43 }
44 fmt.Println(answer)
45
46 fmt.Println("Elapsed time:", time.Since(starttime))
47
48}
1472func (d *Dist) print(b io.Writer, duration time.Duration) {
1473 fmt.Fprintf(b, "=> Rate (per hr): (%5.2f , %10.2f secs)\t Total: (%5d, %20s, %20s)\n", float64(d.Num)/duration.Hours(), d.TotalDuration.Seconds()/duration.Hours(), d.Num, d.TotalDuration, d.MaxDuration)
1474}
24func main() {
25 c := make(chan int)
26 start := time.Now()
27 go skynet(c, 0, 1000000, 10)
28 result := <-c
29 took := time.Since(start)
30 fmt.Printf("Result: %d in %d ms.\n", result, took.Nanoseconds()/1e6)
31}
8func main() {
9 timeAsString := "2012-01-22"
10 fmt.Println(time.Parse("2006-01-01_this-does-not-compile", timeAsString))
11}

Related snippets