1 回答

TA貢獻1770條經(jīng)驗 獲得超3個贊
你想要const shortForm = "2006-01-02 15:04:05"。這有點奇怪,但是time.Parse理解格式的方式是你必須給出這個特定的時間作為例子。請參閱https://golang.org/src/time/format.go上的評論:
// These are predefined layouts for use in Time.Format and Time.Parse.
// The reference time used in the layouts is the specific time:
// Mon Jan 2 15:04:05 MST 2006
// which is Unix time 1136239445. Since MST is GMT-0700,
// the reference time can be thought of as
// 01/02 03:04:05PM '06 -0700
// To define your own format, write down what the reference time would look
// like formatted your way; see the values of constants like ANSIC,
// StampMicro or Kitchen for examples.
您可能可以想象為什么在這里使用預(yù)定義的日期很重要……例如,圖書館需要知道您的意思是 01/02 是 1 月 2 日還是 2 月 1 日。有一個預(yù)定義的日期(巧妙地構(gòu)造以避免重復(fù)值)可以消除歧義。
- 1 回答
- 0 關(guān)注
- 156 瀏覽
添加回答
舉報