把float64 秒 时间格式化
secToSrtTime := func(start, end float64) string { startI := int64(start * 1e9) endI := int64(end * 1e9) // 00:00:00.000 stdTime := func(t time.Duration) string { return fmt.Sprintf("%02d:%02d:%02.3f", int(t.Hours()), int(t.Minutes()), t.Seconds()) } // 不要加换行 return stdTime(time.Duration(startI)) + " --> " + stdTime(time.Duration(endI)) + " line:0% " }
struct 转字符串 str
package main import ( "encoding/json" "fmt" "reflect" ) // 结构体 中的 数据 一定要 开头大写`json:"year" ` type mydata struct { Year1 string Month1 string `json:"month"` Day1 string `json:"day"` } func main3() { mydata_1 := []mydata{{"1", "2", "3"}, {"2", "4", "6"}} json_mydata, resinfo1 := json.Marshal(mydata_1) fmt.Println(string(json_mydata), resinfo1)
字符串 str 转 struct
json_byt1 := []byte(`{"num":613,"strs":["a","b"]}`) var loud_json1 map[string]interface{} _ = json.Unmarshal(json_byt1, &loud_json1) num1 := loud_json1["num"] fmt.Println(num1) fmt.Println(reflect.TypeOf(num1)) }