time.Time.Unix() Function in Golang with Examples Last Updated : 21 Apr, 2020 Comments Improve Suggest changes Like Article Like Report 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 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) Unix() int64 Here, "t" is the stated time. Note: A Unix like operating system frequently stores time as a 32-bit count of seconds. And on the other hand, the Unix() method here returns a 64-bit value so it's period of validity is for billions of years into the past or the future. Return value: It returns "t" as a Unix time which is of type int64. Example 1: C // Golang program to illustrate the usage of // Time.Unix() function // Including main package package main // Importing fmt and time import "fmt" import "time" // Calling main func main() { // Defining t in UTC for Unix method t := time.Date(2020, 11, 14, 11, 30, 32, 0, time.UTC) // Calling Unix method unix := t.Unix() // Prints output fmt.Printf("%v\n", unix) } Output: 1605353432 Example 2: C // Golang program to illustrate the usage of // Time.Unix() function // Including main package package main // Importing fmt and time import "fmt" import "time" // Calling main func main() { // Defining t in UTC for Unix method t := time.Date(2013, 11, 14, 1e3, 3e5, 7e1, 0, time.UTC) // Calling Unix method unix := t.Unix() // Prints output fmt.Printf("%v\n", unix) } Output: 1405987270 Here, the time "t" stated in the above code has values which contain constant "e" which are converted in usual range while conversion. Comment More infoAdvertise with us Next Article time.Time.Unix() Function in Golang with Examples N nidhi1352singh Follow Improve Article Tags : Go Language GoLang-time Similar Reads time.Time.UnixNano() Function in Golang with Examples 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 w 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.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 Like