MCPcopy
hub / github.com/duke-git/lancet / FormatTimeToStr

Function FormatTimeToStr

datetime/datetime.go:204–218  ·  view source on GitHub ↗

FormatTimeToStr convert time to string. Play: https://go.dev/play/p/_Ia7M8H_OvE

(t time.Time, format string, timezone ...string)

Source from the content-addressed store, hash-verified

202// FormatTimeToStr convert time to string.
203// Play: https://go.dev/play/p/_Ia7M8H_OvE
204func FormatTimeToStr(t time.Time, format string, timezone ...string) string {
205 tf, ok := timeFormat[strings.ToLower(format)]
206 if !ok {
207 return ""
208 }
209
210 if timezone != nil && timezone[0] != "" {
211 loc, err := time.LoadLocation(timezone[0])
212 if err != nil {
213 return ""
214 }
215 return t.In(loc).Format(tf)
216 }
217 return t.Format(tf)
218}
219
220// FormatStrToTime convert string to time.
221// Play: https://go.dev/play/p/1h9FwdU8ql4

Callers 2

ExampleFormatTimeToStrFunction · 0.85
TestFormatTimeToStrFunction · 0.85

Calls 1

FormatMethod · 0.45

Tested by 2

ExampleFormatTimeToStrFunction · 0.68
TestFormatTimeToStrFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…