PHP
·
发表于 5年以前
·
阅读量:8410
package main
import (
"fmt"
"time"
)
func main() {
//当前时间
now := time.Now()
//自定义时间段
timeDur := time.Duration(10)*time.Second + time.Duration(1)*time.Minute
fmt.Println(timeDur)
//时间相加
nowAddTime := now.Add(timeDur)
fmt.Println(nowAddTime)
//时间相减,时间差(时间段)
diff := nowAddTime.Sub(now)
fmt.Println(diff) //1m10s
fmt.Println(diff.Hours()) //分为单位显示时间差,0.019444444444444445
fmt.Println(diff.Minutes()) //分为单位显示时间差,1.1666666666666667
fmt.Println(diff.Seconds()) //秒为单位显示时间差,70
//年月日添加
fmt.Println(nowAddTime.AddDate(1,-9,3)) //2019-10-20 18:55:56.654503204 +0800 CS
}