1.golang string数组 转换成string
names := []string{`张三`, `李四`, `王五`}
namesStr := strings.Replace(strings.Trim(fmt.Sprint(names), "[]"), " ", ",", -1)
logs.Error("=== namesStr ===", namesStr) // 张三,李四,王五
2.golang 利用iota定义常量1 2 3 4 ...常量1 2 4 8 ...
const (
_ = iota
TYPE_A // 1
TYPE_B // 2
TYPE_C // 3
TYPE_D // 4
)
const (
TYPE_A1 = 1 << iota // 1
TYPE_B1 // 2
TYPE_C1 // 4
TYPE_D1 // 8
)
3.golang 获取 time.Time 是当前年的第多少天
func GetDaysOfYear(t time.Time) (days int) {
year := t.Year()
mont := int(t.Month())
day := t.Day()
feb := 28
if (year % 100 != 0 && year % 4 == 0) || year % 400 == 0 {
feb = 29
}
monthDays := []int{31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
for index, monthDays := range monthDays {
if index < mont - 1 {
days += monthDays
}
}
return days + day
}