Commit 6ad607ab by zhengqiuyun86

float精度计算

parent 0eaf471d
......@@ -10,10 +10,10 @@ import (
func TestArrayContainsInterface(t *testing.T) {
var areaIds []time.Time
areaIds = append(areaIds, PareDateTime("2022-02-09 22:09:12"))
areaIds = append(areaIds, PareDateTime("2022-03-09 22:09:12"))
areaIds = append(areaIds, PareDateTime("2022-12-09 22:09:12"))
fmt.Println(ArrayContains[time.Time](areaIds, PareDateTime("2022-02-10 22:09:12")))
areaIds = append(areaIds, ParseDateTime("2022-02-09 22:09:12"))
areaIds = append(areaIds, ParseDateTime("2022-03-09 22:09:12"))
areaIds = append(areaIds, ParseDateTime("2022-12-09 22:09:12"))
fmt.Println(ArrayContains[time.Time](areaIds, ParseDateTime("2022-02-10 22:09:12")))
}
func TestDifference(t *testing.T) {
......
......@@ -27,12 +27,12 @@ func FormatDateMillTime(dateTime time.Time) string {
return dateTime.Format(formatSimple0)
}
func PareDateStart(date string) time.Time {
func ParseDateStart(date string) time.Time {
stamp, _ := time.ParseInLocation(formatSimple1, date+" 00:00:00", time.Local)
return stamp
}
func PareDateTime(dateTime string) time.Time {
func ParseDateTime(dateTime string) time.Time {
stamp, _ := time.ParseInLocation(formatSimple1, dateTime, time.Local)
return stamp
}
......@@ -66,7 +66,7 @@ func TimeSubDays(t1, t2 time.Time) int {
}
}
// TimeSubMinute t1比t2多多少分钟
// TimeSubMinute t1比t2多多少分钟,向上取整
func TimeSubMinute(t1, t2 *time.Time) int {
if t1.Location().String() != t2.Location().String() {
return -1
......@@ -75,6 +75,15 @@ func TimeSubMinute(t1, t2 *time.Time) int {
return int(math.Ceil(seconds / 60)) //向上取整
}
// TimeSubMinuteFloor t1比t2多多少分钟,向上取整
func TimeSubMinuteFloor(t1, t2 *time.Time) int {
if t1.Location().String() != t2.Location().String() {
return -1
}
seconds := t1.Sub(*t2).Seconds()
return int(math.Floor(seconds / 60)) //向上取整
}
func MilSecond(time time.Time) int64 {
return time.UnixNano() / 1e6
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment