Documentation ¶
Overview ¶
Package timefmt provides functions for formatting and parsing date time strings.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendFormat ¶
AppendFormat appends formatted time string to the buffer.
Example ¶
t := time.Date(2020, time.July, 24, 9, 7, 29, 0, time.UTC) buf := make([]byte, 0, 64) buf = append(buf, '(') buf = timefmt.AppendFormat(buf, t, "%Y-%m-%d %H:%M:%S") buf = append(buf, ')') fmt.Println(string(buf))
Output: (2020-07-24 09:07:29)
func Format ¶
Format time to string using the format.
Example ¶
t := time.Date(2020, time.July, 24, 9, 7, 29, 0, time.UTC) str := timefmt.Format(t, "%Y-%m-%d %H:%M:%S") fmt.Println(str)
Output: 2020-07-24 09:07:29
func Parse ¶
Parse time string using the format.
Example ¶
str := "2020-07-24 09:07:29" t, err := timefmt.Parse(str, "%Y-%m-%d %H:%M:%S") if err != nil { log.Fatal(err) } fmt.Println(t)
Output: 2020-07-24 09:07:29 +0000 UTC
func ParseInLocation ¶ added in v0.1.3
ParseInLocation parses time string with the default location. The location is also used to parse the time zone name (%Z).
Example ¶
loc := time.FixedZone("JST", 9*60*60) str := "2020-07-24 09:07:29" t, err := timefmt.ParseInLocation(str, "%Y-%m-%d %H:%M:%S", loc) if err != nil { log.Fatal(err) } fmt.Println(t)
Output: 2020-07-24 09:07:29 +0900 JST
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.