Skip to content

golang的time包:秒、毫秒、纳秒时间戳输出 #7

@AlexZ33

Description

@AlexZ33

10位数的时间戳是以 秒 为单位;
13位数的时间戳是以 毫秒 为单位;
19位数的时间戳是以 纳秒 为单位;

golang中可以这样写:


package main

import (
	"time"
	"fmt"
)

func main() {
	fmt.Printf("时间戳(秒):%v;\n", time.Now().Unix())
	fmt.Printf("时间戳(纳秒):%v;\n",time.Now().UnixNano())
	fmt.Printf("时间戳(毫秒):%v;\n",time.Now().UnixNano() / 1e6)
	fmt.Printf("时间戳(纳秒转换为秒):%v;\n",time.Now().UnixNano() / 1e9)
}

时间戳(秒):1530027865;
时间戳(纳秒):1530027865231834600;
时间戳(毫秒):1530027865231;
时间戳(纳秒转换为秒):1530027865;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions