Created
August 16, 2024 08:48
-
-
Save iolalla/fd8b96c550014afc3d92c22a42b7f8de to your computer and use it in GitHub Desktop.
Simple, how can we calculate the what percentage of the year is gone.
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
package main | |
/** how to calculate the percentage of the year in go */ | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
t := time.Now() | |
yearday := t.YearDay() | |
// TODO: What if we are in a leap year | |
perc := (float64(yearday) / float64(365)) * 100 | |
year := t.Year() | |
fmt.Printf("YearDay: %v \n", yearday) | |
fmt.Printf("Year: %v \n", year) | |
fmt.Printf("Perc: %f \n", perc) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment