完成gtime基本自定义时间格式转换功能

This commit is contained in:
John
2018-07-11 17:41:39 +08:00
parent 9f75d6c764
commit cc0d6d7880
3 changed files with 28 additions and 4 deletions

View File

@ -113,7 +113,7 @@ func (t *Time) Format(format string) string {
s += r
}
} else {
s += f
s += string(format[i])
}
}
i++

View File

@ -7,9 +7,12 @@ import (
func main() {
formats := []string{
"Y-m-d H:i:s",
"2006-01-02T15:04:05Z07:00",
"2006-01-02T15:04:05.999999999Z07:00",
"Y-m-d H:i:s.u",
"D M d H:i:s e O Y",
// 可以使用转义字符转移有意义的格式字母
"T\\i\\m\\e \\i\\s: h:i:s a",
// format格式不支持标准库格式混合相互隔离
"2006-01-02T15:04:05.000000000Z07:00",
}
t := gtime.Now()
for _, f := range formats {

View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"gitee.com/johng/gf/g/os/gtime"
)
func main() {
formats := []string{
"2006-01-02 15:04:05.000",
"Mon Jan _2 15:04:05 MST 2006",
"Time is: 03:04:05 PM",
"2006-01-02T15:04:05.000000000Z07:00 MST",
}
t := gtime.Now()
for _, f := range formats {
fmt.Println(f)
fmt.Println(t.Layout(f))
fmt.Println()
}
}