Home  >  Article  >  Backend Development  >  How to get the first few days of the current time in golang

How to get the first few days of the current time in golang

silencement
silencementOriginal
2019-12-25 13:13:145699browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn