strconv.Itoa(time.Nanoseconds()) – 错误

huangapple go评论66阅读模式
英文:

strconv.Itoa(time.Nanoseconds()) - Error

问题

我写了一段类似这样的Go代码,strconv.Itoa(time.Nanoseconds())。但是,它给我返回了这个错误信息:"无法将time.Nanoseconds()(类型为int64)作为函数参数的int类型使用"。我该如何解决这个问题?

英文:

I write one go code like this, strconv.Itoa(time.Nanoseconds()). But, it is giving me this error "cannot use time.Nanoseconds() (type int64) as type int in function argument". How can I solve this ?

答案1

得分: 3

例如,

package main

import (
	"fmt"
	"strconv"
	"time"
)

func main() {
	t := strconv.FormatInt(time.Nanoseconds(), 10)
	fmt.Println(t)
}

输出:

1322756865962046000
英文:

For example,

package main

import (
	"fmt"
	"strconv"
	"time"
)

func main() {
	t := strconv.FormatInt(time.Nanoseconds(), 10)
	fmt.Println(t)
}

Output:

1322756865962046000

答案2

得分: 2

如果你遇到了这样的错误,只需按照编译器给出的方式进行转换。
例如:

strconv.Itoa(int(time.Nanoseconds()))
英文:

if you got an error like this, just cast it the way the compiler told it.
i.e.:

strconv.Itoa(int(time.Nanoseconds()))

huangapple
  • 本文由 发表于 2011年12月1日 23:53:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/8344210.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定