」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 將字符串時間轉換為Go時間結構的技巧

將字符串時間轉換為Go時間結構的技巧

發佈於2025-04-18
瀏覽:196

How to Convert a String Time to a Go Time Structure? 
將字符串時間轉換為go go go go time struction

當處理特定格式的字符串時間值時,會出現一個常見問題,該格式無法識別默認時間。要解析此字符串,我們可以根據其特定格式定義自己的佈局字符串。

YYYY: Four-digit ye​​ar

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從時代軟件包提供的標準選項。
最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3