一个api函数 要求返回datatime用GO封装函数接受

hellsam · · 741 次点击
``` go func GetApi()(create time.Time){ result:= http.get("http://url/api=xxxxxxxxxx") //这个返回interface{} return result } ``` 你这个 result 不可能是 time 类型 他只能是一个 byte 或者 json 之类的 ``` go resp, _ := http.Get("url") body, _ := ioutil.ReadAll(resp.Body) log.Println(string(body)) // 这里的 body 是一个 []byte 类型,你接下来只需要 []byte 转 int64 获得 timestamp // 再转时间就行了 time.Unix(timestamp, 0).Format("2006-01-02 15:04:05") ```
#10
更多评论
手写的代码 见谅 可能有些大小写没写正确。
#1
额 有人回复? 没人我等会再问问
#2