如下函数,将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)
有疑问加站长微信联系(非本文作者)