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초 ")) | |
} | |
} |
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
아 처음이 12시 이전이라 날이 앞으로 넘어가는 경우엔 12보다 높겠지.