英文:
Cast from renamed type in google go
问题
我正在尝试编写适用的方法将appengine/datastore.Time类型转换为字符串。
这个类型被声明为type Time int64
但是当我尝试将它用作int64值时:
localTime := time.SecondsToLocalTime(t/1000)
我收到错误消息
> 无法将t / 1000(类型为datastore.Time)作为int64类型传递给函数参数
从int64赋值给Time类型的变量是成功的,但是如何将其强制转换回来呢?
英文:
I'm trying to write suitable method of converting appengine/datastore.Time type to string.
This type is declared as type Time int64
But when i'm trying to use it as int64 value:
localTime := time.SecondsToLocalTime(t/1000)
I'm receiving error message
> cannot use t / 1000 (type
> datastore.Time) as type int64 in
> function argument
Assignment from int64 to Time typed variable is successfull, but how can i cast it back?
答案1
得分: 4
像这样做
time.SecondsToLocalTime(int64(t)/1000)
在转换的文档中查看更多信息
英文:
do it like
time.SecondsToLocalTime(int64(t)/1000)
See more in the documentation about Conversions
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论