Golang time.Time.Year() and YearDay() functions example
package time
Golang time.Time.Year() and YearDay() functions usage example. YearDay() function is useful in calculating how many days have lapsed in a year from a given date.
For example :
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println("Today : ", now.Format(time.ANSIC))
fmt.Println("Year : ", now.Year())
fmt.Printf("We are now %d days into year %d\n", now.YearDay(), now.Year())
}
Sample output :
Today : Tue Aug 11 17:07:49 2015
Year : 2015
We are now 223 days into year 2015
References :
Advertisement
Something interesting
Tutorials
+11.6k Swift : Convert (cast) Float to String
+6k Golang : Compound interest over time example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+43.2k Golang : Convert []byte to image
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+12.6k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+10.9k Nginx : TLS 1.2 support
+17.6k Golang : Upload/Receive file progress indicator
+6.6k Golang : Totalize or add-up an array or slice example
+6.1k Golang : Debug with Godebug
+17.5k Golang : Clone with pointer and modify value
+5.6k Swift : Get substring with rangeOfString() function example