función time.Weekday() en Golang con ejemplos

En el lenguaje Go, los paquetes de tiempo brindan funcionalidad para determinar y ver el tiempo. La función Weekday() en el idioma Go se utiliza para comprobar el nombre del día en inglés. Además, esta función se define en el paquete de tiempo . Aquí, debe importar el paquete «tiempo» para poder usar estas funciones.

Sintaxis:

func (d Weekday) String() string

Valor devuelto: Devuelve el nombre del día en inglés.

Ejemplo 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)
}

Producción:

Weekday is:  Thursday

Ejemplo 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))
}

Producción:

Weekday in number is:  4

Publicación traducida automáticamente

Artículo escrito por nidhi1352singh y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *