github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/timex/README.md (about) 1 # jsontime 2 3 Parsing time in JSON compatible with some common format. 4 5 ```go 6 import ( 7 "encoding/json" 8 "github.com/bingoohuang/gg/pkg/timex" 9 ) 10 11 type Msg struct { 12 O jsontime.Time 13 A jsontime.Time 14 B jsontime.Time 15 C jsontime.Time 16 E jsontime.Time 17 F jsontime.Time 18 D jsontime.Time `json:"d"` 19 } 20 21 func main() { 22 j := `{ 23 "O": "", 24 "A": "1604022846", 25 "F": 1604022846000, 26 "B": "2020-03-18 10:51:54.198", 27 "C": "2020-03-18 10:51:54,198", 28 "E": "2020-03-18T10:51:54,198", 29 "d": "2020-03-18T10:51:54.198000Z", 30 "G": "XYZ" 31 }` 32 33 var msg Msg 34 err := json.Unmarshal([]byte(j), &msg) 35 } 36 ``` 37 38 supporting time format: 39 40 1. direct milliseconds 41 1. string format of millis seconds 42 1. string format of yyyy-MM-dd HH:mm:ss.SSS 43 1. string format of yyyy-MM-dd HH:mm:ss,SSS 44 1. string format of yyyy-MM-ddTHH:mm:ss.SSS 45 1. string format of yyyy-MM-ddTHH:mm:ss,SSS 46 1. string format of yyyy-MM-dd HH:mm:ss.SSSSSSZ 47 1. string format of yyyy-MM-dd HH:mm:ss,SSSSSSZ 48 1. 完整年月日时分秒的字符串