由于 Golang Weekday 返回的是日期的英文周几,需要加个 Map 转换为中文。
package main
import (
"fmt"
"time"
)
var WeekDayMap = map[string]string{
"Monday": "周一",
"Tuesday": "周二",
"Wednesday": "周三",
"Thursday": "周四",
"Friday": "周五",
"Saturday": "周六",
"Sunday": "周日",
}
func main() {
date := "2021-05-07"
t, err := time.Parse("2006-01-02", date)
if err != nil {
panic(err)
}
fmt.Println(t.Weekday())
fmt.Println(WeekDayMap[t.Weekday().String()])
}
运行输出结果:
Friday
周五
微信关注我哦 👍
我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式