Something like python timedelta in golang

package main

import (
        "fmt"
        "time"
)

func main() {
        baseTime := time.Date(1980, 1, 6, 0, 0, 0, 0, time.UTC)
        date := baseTime.Add(1722*7*24*time.Hour + 24*time.Hour + 66355*time.Second)
        fmt.Println(date)
}

Playground


Output

2013-01-07 18:25:55 +0000 UTC

jnml's answer works and is more idiomatic go. But to illustrate why your original code didn't work, all you have to do is change one line.

date := base.Add(time.Duration(nanosecs)) will cast the nanosecs to a time.Duration which is the type that Add expects as opposed to int64. Go will not automatically cast a type for you so it complained about the type being int64.

Tags:

Timedelta

Go