gorm time.time 某个时间 减去十分钟
要将某个时间减去十分钟,您可以使用 time.Time 中的 Add 方法和 time.Duration 中的 - 运算符。下面是一个示例代码片段:
import (
"fmt"
"time"
)
func main() {
// 假设要减去的时间为 2021-10-10 10:30:00
t := time.Date(2021, 10, 10, 10, 30, 0, 0, time.UTC)
// 将十分钟转换为 time.Duration 类型
d := 10 * time.Minute
// 减去十分钟
newTime := t.Add(-d)
// 输出结果
fmt.Println(newTime)
}
这将输出 2021-10-10 10:20:00 +0000 UTC,即原始时间减去十分钟后的时间。
原文地址: https://www.cveoy.top/t/topic/wZv 著作权归作者所有。请勿转载和采集!