Skip to content

Instantly share code, notes, and snippets.

@iolalla
Created August 16, 2024 08:48
Show Gist options
  • Save iolalla/fd8b96c550014afc3d92c22a42b7f8de to your computer and use it in GitHub Desktop.
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.
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