https://github.com/johejo/extratime
An extra time package for unmarshalling and marshalling json and xml.
https://github.com/johejo/extratime
go golang json time xml
Last synced: about 2 months ago
JSON representation
An extra time package for unmarshalling and marshalling json and xml.
- Host: GitHub
- URL: https://github.com/johejo/extratime
- Owner: johejo
- License: mit
- Created: 2020-05-18T16:03:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T20:46:20.000Z (about 4 years ago)
- Last Synced: 2025-05-21T21:08:09.332Z (about 1 year ago)
- Topics: go, golang, json, time, xml
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# extratime
An extra package for unmarshalling and marshalling time format to json and xml.
[](https://github.com/johejo/extratime/actions?query=workflow%3Aci)
[](https://codecov.io/gh/johejo/extratime)
[](https://pkg.go.dev/github.com/johejo/extratime)
[](https://goreportcard.com/report/johejo/extratime)
## Supported Formats
- ANSIC
- UnixDate
- RFC1123
- RFC1123Z
- RFC822
- RFC822Z
- RFC850
- Kitchen
- Stamp
- StampMilli
- StampMicro
- StampNano
- RubyDate
- UnixTimeStamp
## Install
```
go get github.com/johejo/extratime
```
## Example
```go
package extratime_test
import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/johejo/extratime"
)
type A struct {
XMLName xml.Name `xml:"a"`
Text string `xml:",chardata"`
B extratime.RFC1123 `xml:"b"`
}
func Example() {
// xml
const x = "Mon, 02 Jan 2006 15:04:05 MST"
var a A
if err := xml.Unmarshal([]byte(x), &a); err != nil {
panic(err)
}
xb, err := xml.Marshal(a)
if err != nil {
panic(err)
}
fmt.Println(string(xb))
// json
const j = `{"t": "Mon, 02 Jan 2006 15:04:05 MST"}`
var m map[string]extratime.RFC1123
if err := json.Unmarshal([]byte(j), &m); err != nil {
panic(err)
}
jb, err := json.Marshal(m)
if err != nil {
panic(err)
}
fmt.Println(string(jb))
// Output:
// Mon, 02 Jan 2006 15:04:05 MST
// {"t":"Mon, 02 Jan 2006 15:04:05 MST"}
}
```
## License
MIT
## Author
Mitsuo Heijo (@johejo)