Skip to content
Home » How to demonstrate the Nanoseconds() function in Golang

How to demonstrate the Nanoseconds() function in Golang

Learn about How to demonstrate the Nanoseconds() function in Golang in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

How to demonstrate the Nanoseconds() function in Golang

// Golang program to demonstrate the
// Nanoseconds() function

package main

import "fmt"
import "time"

func main() {
	t, _ := time.ParseDuration("3h32m30s")
	fmt.Printf("Total Nanoseconds are: %d", t.Nanoseconds())
}

Here, we created t variable initialized using time.ParseDuration() function. Then get total nanoseconds using Nanoseconds() function. The Nanoseconds() function returns int64 value.

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
How to demonstrate the Seconds() function in Golang
How to print date and time according to the specified location in Golang