time.Time.UnixNano() Function in Golang with Examples Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In Go language, time packages supply functionality for determining as well as viewing time. The Time.UnixNano() function in Go language is used to yield "t" as a Unix time that is the number of seconds passed from January 1, 1970, in UTC and the output here doesn't rely upon the location connected with t. Moreover, this function is defined under the time package. Here, you need to import the "time" package in order to use these functions. Syntax: func (t Time) UnixNano() int64 Here, "t" is the stated time.Note: Here, the output returned is not defined if the given Unix time in nanoseconds is not formed by an int64 type(which is a date before the year 1678 or after the year 2262). This implies that the result of calling the UnixNano() method on the zero Time is ambiguous.Return value: It returns "t" as a Unix time which is of type int64. Example 1: Go // Golang program to illustrate the usage of // Time.UnixNano() function // Including main package package main // Importing fmt and time import "fmt" import "time" // Calling main func main() { // Defining t in UTC // for UnixNano method t := time.Date(2019, 13, 15, 23, 90, 12, 04, time.UTC) // Calling UnixNano method unixnano := t.UnixNano() // Prints output fmt.Printf("%v\n", unixnano) } Output: 1579134612000000004 Example 2: Go // Golang program to illustrate the usage of // Time.UnixNano() function // Including main package package main // Importing fmt and time import "fmt" import "time" // Calling main func main() { // Defining t in UTC // for UnixNano method t := time.Date(2001, 13, 15, 2e3, 1e1, 12e2, 04e1, time.UTC) // Calling UnixNano method unixnano := t.UnixNano() // Prints output fmt.Printf("%v\n", unixnano) } Output: input 1018254600000000040 Here, the time "t" stated in the above code has values which contain constant "e" but they are converted in usual range while conversion. Comment More infoAdvertise with us Next Article time.Time.UnixNano() Function in Golang with Examples nidhi1352singh Follow Improve Article Tags : Go Language GoLang-time Similar Reads time.Time.Unix() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Unix() function in Go language is used to yield "t" as a Unix time that is the number of seconds passed from January 1, 1970, in UTC and the output here doesn't rely upon the location connected wit 2 min read time.Time.UTC() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.UTC() function in Go language is used to yield "t" with the location that is set to UTC. Moreover, this function is defined under the time package. Here, you need to import the "time" package in or 2 min read time.Unix() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Unix() function in Go language is used to yield the local time which is related to the stated Unix time from January 1, 1970, in UTC. Moreover, this function is defined under the time package. Here, you 2 min read time.Time.Truncate() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Truncate() function in Go language is used to find the output of rounding the stated time "t" to the closest multiple of the given duration "d" from the zero time. Moreover, this function is define 2 min read time.Time.In() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The In() function in Go language is used to find a copy of the stated "t" that represents the identical time instant, but along with the copy's location data that is set to "loc" for display uses. And if "l 2 min read time.Time.UnmarshalBinary() Function in Golang with Examples In Go language, time packages supply functionality for determining as well as viewing time. The UnmarshalBinary() function in Go language is used to implement the encoding.BinaryUnmarshaler interface. Moreover, this function is defined under the time package. Here, you need to import the "time" pack 2 min read time.Time.UnmarshalJSON() Function in Golang with Examples In Go language, time packages supply the functionality for determining as well as viewing time. The UnmarshalJSON() function in Go language is used to implement the json.Unmarshaler interface. The time here is a quoted-string which is in RFC 3339 format. Moreover, this function is defined under the 2 min read time.Until() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Until() function in Go language holds time value t and is used to evaluate the duration until the time t. Moreover, this function is defined under the time package. Here, you need to import the "time" p 2 min read time.Time.Sub() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Sub() function in Go language is used to yield the duration obtained by performing the operation t-u. And if the output here surpasses the maximum or the minimum value that can be stored in a Durat 2 min read time.Time.Add() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Add() function in Go language is used to add the stated time and duration. Moreover, this function is defined under the time package. Here, you need to import the "time" package in order to use the 2 min read Like