test
test
reflect包
type t struct {
name string
}
reflect.Typeof(t) // main.t
reflect.Kind(t) // struct
1.Typeof指变量所属的类型,Kind指变量所属的类别。
const (Invalid Kind = iota,Bool,Int,Int8,Int16,Int32,Int64,Uint,Uint8,Uint16,Uint32,Uint64,Uintptr,Float32,Float64,Complex64,Complex128,Array,Chan,Func,Interface,Map,Ptr,Slice,String,Struct,UnsafePointer)
2.修改接口实际变量的值
Elem()
获取指向原变量的指针
reflect.ValueOf(a).Elem().SetInt(38)
时间转换
todayZero, _ := time.ParseInLocation("2006-01-02", "2021-11-26 15:22:22" time.Local)
评论