Every line of 'time golang' 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.
8 func main() { 9 timeAsString := "2012-01-22" 10 fmt.Println(time.Parse("2006-01-01_this-does-not-compile", timeAsString)) 11 }
1152 func (s *Delete_commandContext) Time() ITimeContext { 1153 var t = s.GetTypedRuleContext(reflect.TypeOf((*ITimeContext)(nil)).Elem(), 0) 1154 1155 if t == nil { 1156 return nil 1157 } 1158 1159 return t.(ITimeContext) 1160 }
6 func 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 }
8 func main() { 9 t := time.Date(2009, time.November, 10, 23, 4, 5, 0, time.UTC) 10 h, m, s := t.Clock() 11 fmt.Println(h, m, s) 12 }
18 func main() { 19 john := person{ 20 name: "John Coltrane", 21 dob: time.Date(1926, time.September, 23, 0, 0, 0, 0, time.UTC), 22 } 23 print(john) 24 noodles := product{ 25 name: "noodles", 26 cost: 235, 27 } 28 print(noodles) 29 print("a string?") 30 }
15 func timeHandler(w http.ResponseWriter, r *http.Request) { 16 t := time.Now().Format(time.RFC1123) 17 Body := "The current time is:" 18 fmt.Fprintf(w, "<h1>%s</h1>", Body) 19 fmt.Fprintf(w, "<h2>%s</h2>\n", t) 20 fmt.Fprintf(w, "Serving: %s\n", r.URL.Path) 21 fmt.Printf("Served time for: %s\n", r.Host) 22 }
60 func timeBridge(b *bridgeConn) { 61 go func() { 62 t := time.Duration(rand.Intn(5)+1) * time.Second 63 time.Sleep(t) 64 log.Printf("killing connection %s after %v\n", b.String(), t) 65 b.Close() 66 }() 67 bridge(b) 68 }
22 func 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 }
39 func main() { 40 41 // Use the time package to get the current date/time. 42 now := time.Now() 43 44 // Subtract 5 nanoseconds from now time using a literal constant. 45 lessFiveNanoseconds := now.Add(-5) 46 47 // Subtract 5 seconds from now using a declared constant. 48 lessFiveSeconds := now.Add(-fiveSeconds) 49 50 // Display the values. 51 fmt.Printf("Now : %v\n", now) 52 fmt.Printf("Nano : %v\n", lessFiveNanoseconds) 53 fmt.Printf("Seconds : %v\n", lessFiveSeconds) 54 }
176 func goTime(t C.pn_timestamp_t) time.Time { 177 if t == 0 { 178 return time.Time{} 179 } 180 return time.Unix(0, int64(t)*int64(time.Millisecond)) 181 }