mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
优化格式化星期值性能
This commit is contained in:
@ -10,6 +10,7 @@ import (
|
||||
"bytes"
|
||||
"github.com/gogf/gf/g/text/gregex"
|
||||
"github.com/gogf/gf/g/text/gstr"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -135,7 +136,7 @@ func (t *Time) Format(format string) string {
|
||||
case 'u':
|
||||
buffer.WriteString(strings.Replace(result, "=u=.", "", -1))
|
||||
case 'w':
|
||||
buffer.WriteString(weekstosint(result))
|
||||
buffer.WriteString(strconv.Itoa(int(t.Weekday())))
|
||||
default:
|
||||
buffer.WriteString(result)
|
||||
}
|
||||
@ -152,19 +153,3 @@ func (t *Time) Format(format string) string {
|
||||
func (t *Time) Layout(layout string) string {
|
||||
return t.Time.Format(layout)
|
||||
}
|
||||
|
||||
// 将字母的星期数字转为数字:0为星期天 6为星期六
|
||||
func weekstosint(week string) string {
|
||||
|
||||
weeks := map[string]string{
|
||||
"Monday": "1",
|
||||
"Tuesday": "2",
|
||||
"Wednesday": "3",
|
||||
"Thursday": "4",
|
||||
"Friday": "5",
|
||||
"Saturday ": "6",
|
||||
"Sunday": "0",
|
||||
}
|
||||
|
||||
return weeks[week]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user