Skip to content
This repository has been archived by the owner on Dec 4, 2022. It is now read-only.

tebeka/jtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flexible JSON time Handling

time.Time marshal to JSON only in one format (RFC3339Nano). jtime.Time embeds time.Time and lets the user set the format via Marshallers.

Example

package main

import (
        "encoding/json"
        "fmt"
        "log"

        "bitbucket.org/tebeka/jtime"
)

type T struct {
        Created jtime.Time `json:"created"`
}

func main() {
        jtime.SetMarshaler(&jtime.UnixMarshaler{})
        data := []byte(`{"created":1382135725}`) // Oct 18, 2013
        t := T{}
        if err := json.Unmarshal(data, &t); err != nil {
                log.Fatalf("error umarshaling: %s\n", err)
        }
        fmt.Println(t.Created) // 2013-10-18 15:35:25 -0700 PDT
}

Contact

https://bitbucket.org/tebeka/jtime

License

MIT (see LICENSE.txt)

About

Flexible time marshal/unmarshal for JSON

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages