[time] YYYY-MM-DD date format 사용하기

천현철·2022년 12월 7일
0

Golang

목록 보기
13/13
post-custom-banner

Datetime Format Layout

const (
	Layout      = "01/02 03:04:05PM '06 -0700" // The reference time, in numerical order.
	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"
)

YYYY-MM-DD

package main

import (
    "fmt"
    "time"
)

const (
    YYYYMMDD = "2006-01-02"
)

func main() {
    now := time.Now().UTC()
    fmt.Println(now.Format(YYYYMMDD))
}
//output: 2022-03-14

DD/MM/YYYY

package main

import (
    "fmt"
    "time"
)

const (
    DDMMYYYY = "02/01/2006"
)

func main() {
    now := time.Now().UTC()
    fmt.Println(now.Format(DDMMYYYY))
}
//output: 14/03/2022

YYYY-MM-DD hh:mm:ss

package main

import (
    "fmt"
    "time"
)

const (
    DDMMYYYYhhmmss = "2006-01-02 15:04:05"
)

func main() {
    now := time.Now().UTC()
    fmt.Println(now.Format(DDMMYYYYhhmmss))
}
//output: 2022-03-14 05:41:33

출처: https://gosamples.dev/date-format-yyyy-mm-dd/

profile
기도하지말고 행동하라
post-custom-banner

0개의 댓글