[Go] Add or subtract seconds from a time.Time value

Created on November 30, 2026

You can pass a duration to time.Time.Add to move a time forward or backward. Multiply the number of seconds by time.Second. A negative duration subtracts time.

package main

import (
    "fmt"
    "time"
)

func main() {
    start := time.Date(2019, time.November, 22, 0, 0, 0, 0, time.UTC)
    const layout = "2006-01-02 15:04:05"
    fmt.Println(start.Format(layout))
    fmt.Println(start.Add(10 * time.Second).Format(layout))
    fmt.Println(start.Add(-10 * time.Second).Format(layout))
}
2019-11-22 00:00:00
2019-11-22 00:00:10
2019-11-21 23:59:50
Go