gpt4 book ai didi

javascript - Go 中的 Date.now() 等价物

转载 作者:IT王子 更新时间:2023-10-29 00:49:13 25 4
gpt4 key购买 nike

在 JavaScript 中,我可以赋值:

var now = Date.now();

然后使用now作为数字变量进行计算

time.Time 类型在 Go 中似乎不能满足这种需求。 JavaScript 的 Date.now() 在 Go 中的等效项是什么?

最佳答案

Date.now() 返回自纪元 UTC 以来的毫秒数

The now() method returns the milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now as a Number.

要在 Go 中获取它,您可以使用:

time.Now().UTC().UnixNano() / 1e6

关于javascript - Go 中的 Date.now() 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36051177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com