Skip to main content

Format

Constants#

const (
FormatDate = "YYYY-MM-DD"
FormatTime = "HH:mm:ss"
FormatYear = "YYYY"
FormatDateTime = "YYYY-MM-DD HH:mm:ss"
)

Format#

func Format(t time.Time, formatStr string) string

Format the date in a commonly used format:

gtime.Format(time.Now(), "YYYY-MM-DD HH:mm:ss")
// => "2021-03-12 21:25:37"

List of all available formats#

FormatOutput
YY18
YYYY2018
M1-12
MM01-12
MMMJan-Dec
MMMMJanuary-December
D1-31
DD01-31
d0-6
ddSu-Sa
dddSun-Sat
ddddSunday-Saturday
H0-23
HH00-23
h1-12
hh01-12
m0-59
mm00-59
s0-59
ss00-59
sss000-999
AAM PM
aam pm

Supported languages#

LanguageName
Englishglocale.ENUS
Chinese (Simplified)glocale.ZHCN
繁体中文(中国香港)glocale.ZHHK
繁体中文(中国香港)glocale.ZHTW
t := gtime.SetLocale(glocale.ZHCN)
t.Format(time.now(), "YYYY年MM月DD日 HH时mm分ss秒")