FormatTimeToStr convert time to string. Play: https://go.dev/play/p/_Ia7M8H_OvE
(t time.Time, format string, timezone ...string)
| 202 | // FormatTimeToStr convert time to string. |
| 203 | // Play: https://go.dev/play/p/_Ia7M8H_OvE |
| 204 | func 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 |
searching dependent graphs…