Skip to content

eosswedenorg-go/unixtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnixTime

Test Go Reference

Simple module to handle unix timestamp json encoding/decoding.

Example

package main

import (
    "encoding/json"
    "fmt"
    "time"

    "github.com/eosswedenorg-go/unixtime"
)

type MyStruct struct {
    Timestamp unixtime.Time
}

func main() {
    var s MyStruct

    input := `{"timestamp": 1205647965800}`

    if err := json.Unmarshal([]byte(input), &s); err != nil {
        panic(err)
    }

    // Output: Decoded: 2008-03-16 06:12:45.800 +0000 UTC
    fmt.Println("Decoded:", s.Timestamp.Time().Format("2006-01-02 15:04:05.000 -0700 MST"))

    s.Timestamp.FromTime(time.Date(2014, 6, 11, 14, 3, 55, int(time.Millisecond) * 625, time.UTC))

    data, err := json.Marshal(s)
    if err != nil {
        panic(err)
    }

    // Output: Encoded: {"Timestamp":1402495435625}
    fmt.Println("Encoded:", string(data))
}

Author

Henrik Hautakoski - Sw/eden - henrik@eossweden.org

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages