将字符串时间转换为go go go go time struction
当处理特定格式的字符串时间值时,会出现一个常见问题,该格式无法识别默认时间。要解析此字符串,我们可以根据其特定格式定义自己的布局字符串。
YYYY: Four-digit year
MM: Two-digit month
DD: Two-digit day
T: Separator of date and timeHH: Two-digit hour
mm: Two-digit分钟
SS:二维第二
- 在字符串
定义后,我们可以将其与time.parse(Parse()一起使用,以将字符串时间值转换为time.parse time time time time time time time time stime stime.prime.press ntime shupter.press(&&&&&&&&uperstuct.parse()。 “ 20171023T183552”
布局:=“ 20060102T150405”
t,err:= time.parse(布局,s)
如果err!= nil {
fmt.println(err)
}- Output:
- 2017-10-23 18:35:52 0000 UTC
- Conclusion
- By customizing the layout string, we can successfully parse string time values into time.Time structures in Go, even if their format differs从时代软件包提供的标准选项。