如下函数,将interface变量in转换为int:

func formatTimeStamp(in interface{}, layout string) (out string) {
    timeStr := in.(int)
    month, err := time.Parse(layout, string(timeStr))
    if err != nil {
        return time.Now().Format(layout)
    }
    return month.Format(layout)
}

查看in具体type:

in.(type)

相关文章:

  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-12-10
  • 2021-07-27
  • 2022-02-18
  • 2021-07-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案