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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试