dougong9987
2017-01-06 10:33
浏览 1.8k
已采纳

time.Duration类型的微秒值转换为毫秒

I am using go-ping ( https://github.com/sparrc/go-ping )library of golang for unprivileged ICMP ping.

timeout := time.Second*1000
interval := time.Second
count := 5
host := p.ipAddr
pinger, cmdErr := ping.NewPinger(host)

pinger.Count = count
pinger.Interval = interval
pinger.Timeout = timeout
pinger.SetPrivileged(false)
pinger.Run()
stats := pinger.Statistics()

latency = stats.AvgRtt  // stats.AvgRtt is time.Duration type
jitter = stats.StdDevRtt// stats.StdDevRtt is time.Duration type

From running this, I am getting latency in milliseconds and jitter in microseconds. I want same unit for both let's say millisecond so when I am doing jitter = stats.StdDevRtt/1000 or jitter = jitter/1000 (to convert microseconds to milliseconds), what I am getting is jitter in nanoseconds :(. Is there any way to get same unit milliseconds for both latency and jitter.

图片转代码服务由CSDN问答提供 功能建议

我正在使用Go-ping( https://github.com/sparrc/go-ping )golang库,用于无特权的ICMP ping。

  timeout:  = time.Second * 1000 
interval:= time.Second 
count:= 5 
host:= p.ipAddr 
pinger,cmdErr:= ping.NewPinger(host)
 
pinger.Count = count 
pinger.Interval =  interval 
pinger.Timeout =超时
pinger.SetPrivileged(false)
pinger.Run()
stats:= pinger.Statistics()
 
latency = stats.AvgRtt // stats.AvgRtt是time.Duration type 
jitter =  stats.StdDevRtt // stats.StdDevRtt是时间。持续时间类型
   
 
 

通过运行此命令,我得到的延迟是毫秒,抖动是微秒。 我想让两个单位都等于毫秒,所以当我执行 jitter = stats.StdDevRtt / 1000 jitter = jitter / 1000 (将微秒转换为毫秒)时,什么 我得到的抖动是纳秒级的:(。有什么办法可以使延迟和抖动都达到相同的单位毫秒。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题