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
'Language > Go' 카테고리의 다른 글
[Go] Gin vs Echo vs Fiber Framework (0) | 2022.08.21 |
---|---|
[Go] Time format (2006-01-02 15:04:05) (0) | 2022.07.20 |
[Go] env file ( godotenv ) (0) | 2022.07.06 |
[Go] net Dial, DialTimeout (check tcp port open) (0) | 2022.07.04 |
[Go] go resty (net/http) (0) | 2022.07.04 |