Last active
July 6, 2022 12:27
-
-
Save nidhi-canopas/b2264acc287d5ae3635b62a6af7ca2cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func AddDays(t time.Time, days int) time.Time { | |
| fmt.Println("currentTime: ", t) | |
| // AddDate(years int, months int, days int) | |
| newTime := t.AddDate(0, 0, days) | |
| fmt.Println("newTime: ", newTime) | |
| return newTime | |
| } | |
| /* add 2 days to current time */ | |
| AddDays(time.Now(), 2) | |
| //output: | |
| currentTime: 2022-07-01 22:28:09.732830978 +0530 IST m=+0.000055105 | |
| newTime: 2022-07-03 22:28:09.732827137 +0530 IST | |
| /* subtract 2 days from current time */ | |
| AddDays(time.Now(), -2) | |
| //output: | |
| currentTime: 2022-07-01 22:28:09.733028278 +0530 IST m=+0.000251917 | |
| newTime: 2022-06-29 22:28:09.733025973 +0530 IST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment