翻阅古今
您自己回答这个问题的简单方法是查看 Go 标准库。包车时间import "time"类型工作日工作日指定一周中的某一天(星期日 = 0,...)。type Weekday intconst (
Sunday Weekday = iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)func(工作日)字符串func (d Weekday) String() stringString 返回当天的英文名称("Sunday", "Monday", ...)。src/time/time.go:// A Weekday specifies a day of the week (Sunday = 0, ...).type Weekday intconst ( Sunday Weekday = iota Monday Tuesday Wednesday Thursday Friday Saturday)var days = [...]string{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",}// String returns the English name of the day ("Sunday", "Monday", ...).func (d Weekday) String() string { if Sunday <= d && d <= Saturday { return days[d] } buf := make([]byte, 20) n := fmtInt(buf, uint64(d)) return "%!Weekday(" + string(buf[n:]) + ")"}包 fmtimport "fmt"纵梁型Stringer 由具有 String 方法的任何值实现,该方法定义该值的“本机”格式。String 方法用于打印作为操作数传递给任何接受字符串的格式或未格式化打印机(如 Print)的值。type Stringer interface {
String() string
}