4 MINDS

4MINDS Gestão de Conhecimento

Go Lang - Date format



const (
    stdLongMonth      = "January"
    stdMonth          = "Jan"
    stdNumMonth       = "1"
    stdZeroMonth      = "01"
    stdLongWeekDay    = "Monday"
    stdWeekDay        = "Mon"
    stdDay            = "2"
    stdUnderDay       = "_2"
    stdZeroDay        = "02"
    stdHour           = "15"
    stdHour12         = "3"
    stdZeroHour12     = "03"
    stdMinute         = "4"
    stdZeroMinute     = "04"
    stdSecond         = "5"
    stdZeroSecond     = "05"
    stdLongYear       = "2006"
    stdYear           = "06"
    stdPM             = "PM"
    stdpm             = "pm"
    stdTZ             = "MST"
    stdISO8601TZ      = "Z0700"  // prints Z for UTC
    stdISO8601ColonTZ = "Z07:00" // prints Z for UTC
    stdNumTZ          = "-0700"  // always numeric
    stdNumShortTZ     = "-07"    // always numeric
    stdNumColonTZ     = "-07:00" // always numeric
)


Exemplo: ISO 8601 - YYYY-MM-DDThh:mm:ss.sTZD, São Paulo



package main

import (
    "fmt"
    "time"
)

func main() {

    date := "2017-01-31T17:27:58-02:00" // date string to parse
    layout := "2006-01-02T15:04:05-07:00" // date layout/format

    location, _ := time.LoadLocation("America/Sao_Paulo")


    newDate, err := time.ParseInLocation(layout, date, location)

    if err != nil {
        fmt.Println("error %v", err)
    } else {
        fmt.Println("Hello, %v", newDate)
    }
}