时间戳与字符串之间相互转换 - Tue, May 7, 2019
时间戳与字符串之间相互转换
// 时间戳
int64 := time.Now().Unix()
// 时间戳字符串
string := strconv.FormatInt(int64,10)
// 时间转字符串
string := time.Now().String()
// 时间转自定格式字符串
string := time.Now().Format(time.RFC3339)
example
package main
import (
"fmt"
"time"
)
func main() {
int64Value := time.Now().Unix()
fmt.Println("timestamp:", int64Value)
stringValue := time.Now().String()
fmt.Println("2006-01-02 15:04:05.999999999 -0700 MST")
fmt.Println(stringValue)
stringValue = time.Now().Format(time.RFC3339)
fmt.Println("RFC3339:", stringValue)
}
timestamp: 1257894000
2006-01-02 15:04:05.999999999 -0700 MST
2009-11-10 23:00:00 +0000 UTC m=+0.000000001
RFC3339: 2009-11-10T23:00:00Z