📜  如何在 Golang 中获取当前工作日?

📅  最后修改于: 2021-10-24 13:17:37             🧑  作者: Mango

借助time.Now().Weekday()函数,我们可以通过导入 time 模块来获取 Golang 中的工作日。

示例#1:在这个示例中,我们可以看到通过使用time.Now().Weekday()函数,我们能够获取工作日。

// Golang program to get the current weekday
package main
  
// Here "fmt" is formatted IO which 
// is same as C’s printf and scanf.
import "fmt"
  
// importing time module
import "time"
  
// Main function
func main() {
  
    // Using time.Now().Weekday() function.
    dt := time.Now().Weekday()
    fmt.Println(dt.String())
}

输出:

Monday

示例#2:

// Golang program to get the current weekday
package main
  
// Here "fmt" is formatted IO which
// is same as C’s printf and scanf.
import "fmt"
  
// importing time module
import "time"
  
// Main function
func main() {
  
    // Using time.Now().Weekday() function
    dt := time.Now().Weekday()
    fmt.Println(int(dt))
  
}

输出:

1