Home > Article > Backend Development > How to get the first few days of the current time in golang
Get the current time
currentTime := time.Now() //currentTime 的结果为go的时间time类型,2018-09-27 13:24:58.287714118 +0000 UTC
Get the time of the previous n days
//获取两天前的时间 currentTime := time.Now() oldTime := currentTime.AddDate(0, 0, -2) //若要获取3天前的时间,则应将-2改为-3 //oldTime 的结果为go的时间time类型,2018-09-25 13:24:58.287714118 +0000 UTC
It is recommended to study "golang tutorial".
The above is the detailed content of How to get the first few days of the current time in golang. For more information, please follow other related articles on the PHP Chinese website!