我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在for循环中创建持续时间-(不匹配的类型int和time.Duration)

I have a loop where I start by a time.Time and I what to add a minute.

 for idx := range keys {
    var a = idx * time.Minute
    var t = tInit.Add(time.Minute * a)
    fmt.Println(t, idx)


 }

Here is my error

invalid operation: idx * time.Minute (mismatched types int and time.Duration)

The operands to numeric operations must have the same type. Convert the int value idx to a time.Duration: var a = time.Duration(idx) * time.Minute

近期文章

  • golang是否会复制整个接收者的值?
  • Go中的字母数字排序
  • 这段具有非缓冲通道的代码是否会在Go中导致goroutine泄漏?
  • 在Go中使用自定义http.Handler时为什么要使用指针?
  • 去模板构造
  • 返回具有数据成员的多态类型
  • 如何在Golang中创建没有字段或方法的顶级对象?
  • 如何在Golang中为Redis(redigo)Pubsub编写更好的Receive()?
  • 语法错误:复合文字中的换行符前需要结尾逗号
  • 如何将接口转换为结构
  • 在Web应用程序中运行计划的任务
  • 使用Golang进行功能测试
  • golang无法写入文本文件:句柄无效
  • Golang var和文字用法
  • 接受interface {}参数的函数如何更新通过引用调用的值?
  • 为什么Benchmark运行六(?)次
  • Golang返回接口
  • 打包去耦
  • 在Golang中解组json
  • Golang断言任何数字浮动

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华