time.Time.YearDay() Function in Golang with Examples
Last Updated :
21 Apr, 2020
In Go language, time packages supplies functionality for determining as well as viewing time. The Time.YearDay() function in Go language is used to find the day of the year as provided by “t”. Where, the range for non-leap years is [1, 365] and for leap years it is [1, 366]. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.
Syntax:
func (t Time) YearDay() int
Here, “t” is the stated time.
Return value: It returns the day of the year as specified by “t”.
Example 1:
package main
import "fmt"
import "time"
func main() {
t := time .Date(2019, 6, 5, 11,
35, 04, 0, time .UTC)
yrday := t.YearDay()
fmt.Printf( "The day of the year " +
"in the 't' specified is: %v\n" , yrday)
}
|
Output:
The day of the year in the 't' specified is: 156
Example 2:
package main
import "fmt"
import "time"
func main() {
t := time .Date(2020, 35, 60,
45, 67, 94, 7567, time .UTC)
yrday := t.YearDay()
fmt.Printf( "The day of the year in " +
"the 't' specified is: %v\n" , yrday)
}
|
Output:
The day of the year in the 't' specified is: 365
Here, the “t” stated above has values that are out of usual range but they are normalized while conversion.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...