GO語言"time"包中"Time.String"類型的用法及代碼示例。
用法:
func(t Time) String() string
String 返回使用格式字符串格式化的時間
"2006-01-02 15:04:05.999999999 -0700 MST"
如果時間具有單調時鍾讀數,則返回的字符串包括最後一個字段"m=±<value>",其中 value 是格式化為十進製秒數的單調時鍾讀數。
返回的字符串用於調試;要獲得穩定的序列化表示,請使用 t MarshalText t MarshalBinary 或 t.Format 與顯式格式字符串。
例子:
package main
import (
"fmt"
"time"
)
func main() {
timeWithNanoseconds := time.Date(2000, 2, 1, 12, 13, 14, 15, time.UTC)
withNanoseconds := timeWithNanoseconds.String()
timeWithoutNanoseconds := time.Date(2000, 2, 1, 12, 13, 14, 0, time.UTC)
withoutNanoseconds := timeWithoutNanoseconds.String()
fmt.Printf("withNanoseconds = %v\n", string(withNanoseconds))
fmt.Printf("withoutNanoseconds = %v\n", string(withoutNanoseconds))
}
輸出:
withNanoseconds = 2000-02-01 12:13:14.000000015 +0000 UTC withoutNanoseconds = 2000-02-01 12:13:14 +0000 UTC
相關用法
- GO Time.Sub用法及代碼示例
- GO Time.Equal用法及代碼示例
- GO Time.After用法及代碼示例
- GO Time.Format用法及代碼示例
- GO Time.AppendFormat用法及代碼示例
- GO Time.AddDate用法及代碼示例
- GO Time.Truncate用法及代碼示例
- GO Time.Date用法及代碼示例
- GO Time.Round用法及代碼示例
- GO Time.Add用法及代碼示例
- GO Time.GoString用法及代碼示例
- GO Time.Day用法及代碼示例
- GO Time.Unix用法及代碼示例
- GO Time.Before用法及代碼示例
- GO Title用法及代碼示例
- GO Tick用法及代碼示例
- GO TrailingZeros8用法及代碼示例
- GO Tx.ExecContext用法及代碼示例
- GO Template用法及代碼示例
- GO ToTitle用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Time.String。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。