生日判断星座【GO】

星座列表

const (
	Aries       = "aries"
	Taurus      = "taurus"
	Gemini      = "gemini"
	Cancer      = "cancer"
	Leo         = "leo"
	Virgo       = "virgo"
	Libra       = "libra"
	Scorpio     = "scorpio"
	Sagittarius = "sagittarius"
	Capricorn   = "capricorn"
	Aquarius    = "aquarius"
	Pisces      = "pisces"
)

生日转换为星座

package main

import (
	"fmt"
	"time"
)

func getZodiac(month int, day int) string {
	switch {
	case month == 12 && day >= 22:
		return "摩羯座"
	case month == 1 && day <= 19:
		return "摩羯座"
	case month == 1 && day >= 20:
		return "水瓶座"
	case month == 2 && day <= 18:
		return "水瓶座"
	case month == 2 && day >= 19:
		return "双鱼座"
	case month == 3 && day <= 20:
		return "双鱼座"
	case month == 3 && day >= 21:
		return "白羊座"
	case month == 4 && day <= 19:
		return "白羊座"
	case month == 4 && day >= 20:
		return "金牛座"
	case month == 5 && day <= 20:
		return "金牛座"
	case month == 5 && day >= 21:
		return "双子座"
	case month == 6 && day <= 20:
		return "双子座"
	case month == 6 && day >= 21:
		return "巨蟹座"
	case month == 7 && day <= 22:
		return "巨蟹座"
	case month == 7 && day >= 23:
		return "狮子座"
	case month == 8 && day <= 22:
		return "狮子座"
	case month == 8 && day >= 23:
		return "处女座"
	case month == 9 && day <= 22:
		return "处女座"
	case month == 9 && day >= 23:
		return "天秤座"
	case month == 10 && day <= 22:
		return "天秤座"
	case month == 10 && day >= 23:
		return "天蝎座"
	case month == 11 && day <= 21:
		return "天蝎座"
	case month == 11 && day >= 22:
		return "射手座"
	case month == 12 && day <= 21:
		return "射手座"
	default:
		return "未知星座"
	}
}

func main() {
	var timestamp int64
	fmt.Println("请输入您的出生时间戳(秒级): ")
	fmt.Scanln(&timestamp)

	// 将时间戳转换为 time.Time 对象
	t := time.Unix(timestamp, 0)

	// 获取月份和日期
	month := int(t.Month())
	day := t.Day()

	// 确定星座
	zodiac := getZodiac(month, day)
	fmt.Printf("您的星座是: %s\n", zodiac)
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JavaPub-rodert

谢谢老板

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值