Created
June 25, 2020 05:56
-
-
Save ezaurum/1a1e9db21c1ad24ef7e04deb789bacf1 to your computer and use it in GitHub Desktop.
시간 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
t := time.Now() | |
if t.Hour() > 12 { | |
fmt.Println(t.Format("2006년 1월 2일 오후 3시 4분 5초 ")) | |
} else { | |
fmt.Println(t.Format("2006년 1월 2일 오전 3시 4분 5초 ")) | |
} | |
t2 := t.Add(-time.Hour * 12) | |
if t2.Hour() > 12 { | |
fmt.Println(t2.Format("2006년 1월 2일 오후 3시 4분 5초 ")) | |
} else { | |
fmt.Println(t2.Format("2006년 1월 2일 오전 3시 4분 5초 ")) | |
} | |
} |
질문있습니다!
15번째 줄에 있는
t2 := t.Add(-time.Hour * 12)
이걸 해석하면t2에다가 t의 시간(Hour)에 -12한 값이 들어가는 건가요?
예압. 맞습니다.
그러면 16번째 줄에
if t2.Hour() > 12
요기는 t2자체가 t에서 -12된 값이 들어왔는데 t2.hour()가 12보다 높은 경우 (16번째 줄의 if문이 발동하는 경우)는 언제인가요?
그러면 16번째 줄에
if t2.Hour() > 12
요기는 t2자체가 t에서 -12된 값이 들어왔는데 t2.hour()가 12보다 높은 경우 (16번째 줄의 if문이 발동하는 경우)는 언제인가요?
아 처음이 12시 이전이라 날이 앞으로 넘어가는 경우엔 12보다 높겠지.
https://golang.org/pkg/time/#example_Time_Add
13시 - 12 시 이런 산수 계산이 아니고 시간 자체를 움직이는 계산.
의문이 풀렸습니다 감사합니다!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
질문있습니다!
15번째 줄에 있는
t2 := t.Add(-time.Hour * 12)
이걸 해석하면
t2에다가 t의 시간(Hour)에 -12한 값이 들어가는 건가요?