Questions about golang multiply duration, golang multiply time duration, golang int to duration, golang convert int to time.Duration, or errors like mismatched types int and time.Duration all come down to one rule: time.Duration is its own named type (an int64 count of nanoseconds), not a plain int. Multiplication uses the same type rules as the rest of Go: typed int variables do not mix with Duration without a conversion, while untyped integer constants can adopt Duration in the right context. For constants in general, see arrays and constants in Go.
Tested with Go 1.24 on Linux.
mismatched types int and time.Duration
time.Duration is defined as nanoseconds. Constants like time.Second already have type time.Duration. If one side of * is a typed int, the compiler stops:
package main
import (
"fmt"
"time"
)
func main() {
var timeout = 3
fmt.Println(timeout * time.Second)
}./main.go:10:14: invalid operation: timeout * time.Second (mismatched types int and time.Duration)That message is what people paste when they search golang mismatched types int and time.Duration or int to duration golang after a failed multiply.
golang multiply time duration with constants or untyped literals
Untyped constants (including const timeout = 3) can participate in duration math because the compiler still has flexibility about their type:
const timeout = 3
func sleep() {
time.Sleep(timeout * time.Second)
}Untyped integer literals next to a Duration work the same way:
time.Sleep(3 * time.Second)Both are common golang time duration example patterns.
golang int to time.Duration (typed variables)
Once you have a typed int (or int32, int64, …), convert before multiplying:
timeout := 3
time.Sleep(time.Duration(timeout) * time.Second)You can also write time.Second * time.Duration(timeout); multiplication commutes.
If your integer already means nanoseconds, use time.Duration(n) alone. If it means milliseconds:
ms := 500
d := time.Duration(ms) * time.MillisecondPick the unit that matches what the integer represents—golang convert int to time.Duration is really “interpret this int in some unit, then scale by that unit’s Duration constant.”
Division and rounding
time.Duration values divide by integers with / when the divisor is an integer type compatible with the operation, or divide two Durations to get a ratio. For human rounding, see time.Round, Truncate.
go time.duration max value overflow int64 nanoseconds
Duration stores nanoseconds as int64, so the maximum is roughly 9.2e18 ns (about 290 years). Multiplying two large numbers as time.Duration(a) * time.Duration(b) is rarely what you want and can overflow silently. Typical safe pattern: convert the count only, then multiply by one unit constant:
seconds := int64(3600)
d := time.Duration(seconds) * time.SecondIf seconds * int64(time.Second) would exceed math.MaxInt64, the result wraps—validate inputs for long-running timers.
Summary
Golang multiply duration and golang multiply time duration boil down to using either untyped constants/literals or explicit time.Duration(...) casts so both sides of * agree. The compiler error mismatched types int and time.Duration means you used a typed integer without converting. For golang int to time.Duration, multiply time.Duration(n) by time.Second, time.Millisecond, or another unit constant that matches your data. Remember int64 nanoseconds limits and overflow when values get huge.

