iso8601

package module
v0.0.0-...-861d1ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2014 License: MIT Imports: 1 Imported by: 2

README

iso8601

iso8601 is a simple Go package for encoding time.Time in JSON in ISO 8601 format, without subsecond resolution or time zone info.

package main

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

	"github.com/joeshaw/iso8601"
)

func main() {
	t := time.Now()

	// Standard JSON format
	// "2014-03-25T16:15:25.701623113-04:00"
	data, _ := json.Marshal(t)
	fmt.Println(string(data))

	// ISO8601 JSON format
	// "2014-03-25T16:15:25"
	data, _ = json.Marshal(iso8601.Time(t))
	fmt.Println(string(data))

	// Output after decoding back to go.  Note the loss of
	// precision and time zone info.
	// 2014-03-25 16:15:25 +0000 +0000
	var t2 iso8601.Time
	json.Unmarshal(data, &t2)
	fmt.Println(t2)
}

Documentation

Overview

The iso8601 package encodes and decodes time.Time in JSON in ISO 8601 format, without subsecond resolution or time zone info.

Index

Constants

View Source
const Format = "2006-01-02T15:04:05"

Variables

This section is empty.

Functions

This section is empty.

Types

type Time

type Time time.Time

func New

func New(t time.Time) Time

New constructs a new iso8601.Time instance from an existing time.Time instance. This causes the nanosecond field to be set to 0, and its time zone set to a fixed zone with no offset from UTC (but it is *not* UTC itself).

func (Time) MarshalJSON

func (it Time) MarshalJSON() ([]byte, error)

func (Time) String

func (it Time) String() string

func (*Time) UnmarshalJSON

func (it *Time) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL