[Go] Covert Time Unix to UTC

Go 에서 Unix time to UTC time 으로 변경 할 때가 종종 있어서 기록

 

func main() {
	t := time.Unix(1658322376, 0)
	fmt.Println(t)
}

2022-07-20 22:06:16 +0900 KST
 
 
 
func time.Unix(sec int64, nsec int64) time.Time

Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest int64 value).

 

 

 

 

참고로 현재시간 UTC, Unix 구하는 방법

func main() {
	tUTC := time.Now().UTC()
	tUnix := time.Now().Unix()

	fmt.Println(tUTC)
	fmt.Println(tUnix)
}

2022-07-20 13:08:19.12948 +0000 UTC
1658322499

 

 

 

 

 

작업 기록과 샘플 코드는 GitHub에도 정리해두고 있어요.

GitHub 팔로우

Continue Reading

이전 글 / 다음 글