package common import ( "strconv" "time" ) // 时间类型 , 时间差计算 func TimeDifference(time2 time.Time ,time1 time.Time) int { timecc := strconv.FormatInt(time2.Unix()-time1.Unix(),10) timec,err := strconv.Atoi(timecc) if err != nil { return 0 } return timec } // 字符串类型 , 时间差计算 func TimeStrDifference(time2 string ,time1 string) int { time11, _ := time.ParseInLocation("2006-01-02 03:04:05", time1, time.Local) timte21, _ := time.ParseInLocation("2006-01-02 03:04:05", time1, time.Local) return TimeDifference(timte21 ,time11) } // 64位浮点型转字符串 func Float64ToStr(num float64) string { return strconv.FormatFloat(num, 'f', 13, 64) } // 字符串转64位浮点型 func StrToFloat64(str string) float64 { fl,_ :=strconv.ParseFloat(str, 64) return fl } // 字符串转时间类型 func StrToTime(duestr string) time.Time { duetimecst, _ := time.ParseInLocation("2006-01-02 03:04:05", duestr, time.Local) return duetimecst } func TimeToStr(time time.Time) string { str := time.Format("2006-01-02 03:04:05") return str }