Last active
December 3, 2020 10:36
-
-
Save jeffotoni/99e65d2432055db53766701818ae42ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Em Go a formatação de tempo é única e diferente. | |
// Em vez de ter um formato convencional para imprimir a data | |
// Go usa a data de referência 20060102150405 que parece sem sentido | |
// mas na verdade tem um motivo, pois é 1 2 3 4 5 6 no comando Posix date: | |
// Mon Jan 2 15:04:05 -0700 MST 2006 | |
// 0 1 2 3 4 5 6 | |
// O fuso horário é 7, mas fica no meio, então, no final, o formato é | |
// semelhante a 1 2 3 4 5 7 6 | |
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
const ( | |
ANSIC = "Mon Jan _2 15:04:05 2006" | |
UnixDate = "Mon Jan _2 15:04:05 MST 2006" | |
RubyDate = "Mon Jan 02 15:04:05 -0700 2006" | |
RFC822 = "02 Jan 06 15:04 MST" | |
RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone | |
RFC850 = "Monday, 02-Jan-06 15:04:05 MST" | |
RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST" | |
RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone | |
RFC3339 = "2006-01-02T15:04:05Z07:00" | |
RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00" | |
Kitchen = "3:04PM" | |
// Handy time stamps. | |
Stamp = "Jan _2 15:04:05" | |
StampMilli = "Jan _2 15:04:05.000" | |
StampMicro = "Jan _2 15:04:05.000000" | |
StampNano = "Jan _2 15:04:05.000000000" | |
) | |
func main() { | |
t := time.Now() | |
fmt.Println(t.Format(time.RFC3339Nano)) | |
} | |
// usando sprig ficaria assim | |
// {{$dateF := toDate "2006-01-02T15:04:05.000Z" .inputBody.field.current | unixEpoch}} | |
// ou | |
// {{$dateF := toDate "2006-01-02T15:04:05.999999999Z07:00" .inputBody.field.current | unixEpoch}} | |
// tudo irá depender do formato que teremos no .inputBody.field.current | |
// para testar pode clicar aqui se desejar | |
// https://play.golang.org/p/O2S8ell4-CE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment