Go语言通过日期判断星座

// 获取星座
func GetConstellation(t time.Time) string {
    arr1 := []int{21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22}
    arr2 := []string{"摩羯", "水瓶", "双鱼", "白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手", "摩羯"}
    if t.Day() < arr1[t.Month()-1] {
        return arr2[t.Month()-1]
    } else {
        return arr2[t.Month()]
    }
}

你可能感兴趣的:(Go语言通过日期判断星座)