douhuanchi6586 2017-05-31 12:24
浏览 1700
已采纳

如何使用Go语言获取以毫秒为单位的当前时间? [重复]

This question already has an answer here:

I am trying to get the current time in millisecond using Go language https://golang.org/#

package main
import "fmt"
import "time"
func main() {

    now := time.Now()
    secs := now.Unix()
    nanos := now.UnixNano()
    fmt.Println(now)

    millis := nanos / 1000000
    fmt.Println(millis)

}

When I run the above code using the mentioned website the output I get is following:

2009-11-10 23:00:00 +0000 UTC
1257894000000

I am not able to understand why I am not getting current date as result? I tried the same code on another website https://www.epochconverter.com/ and got the correct result which is following :

Time Now is : 
1496230018

Can someone confirm if the problem is related to my code or is the website that's showing the wrong result?

Thanks

</div>
  • 写回答

1条回答 默认 最新

  • duanhan3067 2017-05-31 12:30
    关注

    It seems like you're running this on the Go playground (play.golang.org). The time is fixed on the Go playground, try running it locally instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100