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 need to import the “time” package in order to use these functions.
func Unix(sec int64, nsec int64) Time
Here, “sec” is seconds which is of type int64 and “nsec” is nanoseconds which is also of type int64.
Note: It is reasonable to permit “nsec” outside the range [0, 999999999]. However, not every “sec” values have a equivalent time value and one analogous value is 1<<63-1, which is the largest int64 value.
Return value: It returns the local time which is equivalent to the stated Unix time from January 1, 1970 in UTC.
1970-01-01 00:04:35 +0000 UTC 1970-01-01 00:00:00.000000566 +0000 UTC 1970-01-01 00:07:35.999999933 +0000 UTC
1970-01-01 00:00:20 +0000 UTC 1970-01-01 02:46:40 +0000 UTC 1969-12-20 10:13:30 +0000 UTC
Here, the parameters of the Unix() method stated in the above code have values that contain a constant “e” which is converted in usual range while conversion.