GO語言"time"包中"Time.Unix"類型的用法及代碼示例。
用法:
func(t Time) Unix() int64
Unix 返回 t 作為 Unix 時間,即自 1970 年 1 月 1 日 UTC 以來經過的秒數。結果不依賴於與 t 關聯的位置。 Unix-like 操作係統通常將時間記錄為 32 位的秒數,但由於這裏的方法返回一個 64 位的值,因此它在過去或未來的數十億年中都有效。
例子:
package main
import (
"fmt"
"time"
)
func main() {
// 1 billion seconds of Unix, three ways.
fmt.Println(time.Unix(1e9, 0).UTC()) // 1e9 seconds
fmt.Println(time.Unix(0, 1e18).UTC()) // 1e18 nanoseconds
fmt.Println(time.Unix(2e9, -1e18).UTC()) // 2e9 seconds - 1e18 nanoseconds
t := time.Date(2001, time.September, 9, 1, 46, 40, 0, time.UTC)
fmt.Println(t.Unix()) // seconds since 1970
fmt.Println(t.UnixNano()) // nanoseconds since 1970
}
輸出:
2001-09-09 01:46:40 +0000 UTC 2001-09-09 01:46:40 +0000 UTC 2001-09-09 01:46:40 +0000 UTC 1000000000 1000000000000000000
相關用法
- 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.String用法及代碼示例
- GO Time.Before用法及代碼示例
- GO Title用法及代碼示例
- GO Tick用法及代碼示例
- GO TrailingZeros8用法及代碼示例
- GO Tx.ExecContext用法及代碼示例
- GO Template用法及代碼示例
- GO ToTitle用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Time.Unix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。