在 Go 语言中,时间包提供了确定和查看时间的功能。 Go 语言的Weekday()函数用于检查当天的英文名称。而且,这个函数是在时间包下定义的。在这里,您需要导入“time”包才能使用这些功能。
句法:
func (d Weekday) String() string
返回值:返回当天的英文名称。
示例 1:
// Golang program to illustrate the usage of
// Weekday() function
// Including main package
package main
// Importing fmt and time
import (
"fmt"
"time"
)
// Main function
func main() {
// Calling Weekday method using
// Now function
weekday := time.Now().Weekday()
// Prints the current weekday
fmt.Println("Weekday is: ", weekday)
}
输出:
Weekday is: Thursday
示例 2:
// Golang program to illustrate the usage of
// Weekday() function
// Including main package
package main
// Importing fmt and time
import (
"fmt"
"time"
)
// Main function
func main() {
// Calling Weekday method using
// Now function
weekday := time.Now().Weekday()
// Prints the current
// weekday in int form
fmt.Println("Weekday in number is: ", int(weekday))
}
输出:
Weekday in number is: 4