package main import ( "fmt" "time" ) func main() { secondsDuration := 10 * time.Second nanoseconds := secondsDuration.Nanoseconds() fmt.Printf("%d nanoseconds", nanoseconds) }
package main import ( "fmt" "time" ) func main() { nanosecondsDuration := 1000 * time.Nanosecond now := time.Now() timeAfter := now.Add(nanosecondsDuration) fmt.Printf("Time after %d nanoseconds: %v\n", nanosecondsDuration.Nanoseconds(), timeAfter) }
package main import ( "fmt" "time" ) func main() { shorterDuration := 50000 * time.Nanosecond longerDuration := 100000 * time.Nanosecond if shorterDuration < longerDuration { fmt.Printf("%d nanoseconds is shorter than %d nanoseconds\n", shorterDuration.Nanoseconds(), longerDuration.Nanoseconds()) } else { fmt.Printf("%d nanoseconds is longer than %d nanoseconds\n", shorterDuration.Nanoseconds(), longerDuration.Nanoseconds()) } }All three examples use the Go Time Duration Nanoseconds package to perform time-related operations in nanoseconds.