Every line of 'golang time difference' 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.
173 func timeago(t int64) string { 174 const ( 175 mm = 60 176 hh = 60 * mm 177 dd = 24 * hh 178 ww = 7 * dd 179 ) 180 now := time.Seconds() 181 dif := now-t 182 if dif>dd { 183 if dif>ww { return time.SecondsToUTC(t).Format("2006/01/02") 184 } else { 185 if dif=mm { 186 m := int(dif/mm) 187 if m>59 { 188 h := dif/hh 189 if h>1 { s="s" } 190 return fmt.Sprintf("%d hour%s ago",h,s) 191 } 192 if m>1 { s="s" } 193 return fmt.Sprintf("%d minute%s ago",m,s) 194 } 195 if dif<5 { return "just now" } 196 return fmt.Sprintf("%d seconds ago",dif) 197 }
149 func diffTimes(a time.Time, b time.Time) interface{} { 150 if a == b { 151 return a 152 } 153 return fmt.Sprintf("%v . . . %v (%v difference)", a, b, b.Sub(a)) 154 }
1018 func TimeDelta(cefTime1, cefTime2 *Time, delta *int64) int32 { 1019 return int32(C.cef_time_delta(cefTime1.toNative(&C.cef_time_t{}), cefTime2.toNative(&C.cef_time_t{}), (*C.longlong)(delta))) 1020 }
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 }
360 func timeDiff(now, prev int64) time.Duration { 361 return time.Duration((now - prev) * time.Nanosecond.Nanoseconds()) 362 }
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 }
38 func (d *goDate) DifferenceAsDuration(compare *goDate) time.Duration { 39 return d.Time.Sub(compare.Time) 40 }
34 func minDuration(d1, d2 time.Duration) time.Duration { 35 if d1 < d2 { 36 return d1 37 } 38 return d2 39 }
120 func timeAgo(ago time.Duration) string { 121 if ago < time.Minute { 122 return "just now" 123 } 124 if ago < time.Hour { 125 return utils.Pluralize(int(ago.Minutes()), "minute") + " ago" 126 } 127 if ago < 24*time.Hour { 128 return utils.Pluralize(int(ago.Hours()), "hour") + " ago" 129 } 130 if ago < 30*24*time.Hour { 131 return utils.Pluralize(int(ago.Hours())/24, "day") + " ago" 132 } 133 if ago < 365*24*time.Hour { 134 return utils.Pluralize(int(ago.Hours())/24/30, "month") + " ago" 135 } 136 return utils.Pluralize(int(ago.Hours()/24/365), "year") + " ago" 137 }
117 func formatTimedelta(d int64) string { 118 u := uint64(d) 119 neg := d < 0 120 if neg { 121 u = -u 122 } 123 secs := u % 60 124 u /= 60 125 mins := u % 60 126 u /= 60 127 hours := u % 24 128 days := u / 24 129 130 if days == 0 { 131 return fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs) 132 } else { 133 return fmt.Sprintf("%dd ", days) + fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs) 134 } 135 }