1

golang 根据生日计算星座和属相

 1 year ago
source link: https://studygolang.com/articles/35745
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

golang 根据生日计算星座和属相

ChenXcc · 大约10小时之前 · 144 次点击 · 预计阅读时间 1 分钟 · 大约8小时之前 开始浏览    

根据生日计算星座

func GetZodiac(month, day int) string {
    month = month - 1
    var (
        DAY_ARR = [12]int{20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22}
        ZODIACS = [13]string{"摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座"}
    )

    if day < DAY_ARR[month] {
        return ZODIACS[month]
    } else {
        return ZODIACS[month+1]
    }
}

根据生日计算属相

func GetChineseZodiac(year int) string {
    var CHINESE_ZODIACS = [12]string{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}
    if year > 1900 {
        return CHINESE_ZODIACS[(year-1900)%len(CHINESE_ZODIACS)]
    } else {
        return ""
    }
}

golang 工具库

https://github.com/xbmlz/gct


有疑问加站长微信联系(非本文作者))

280

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK