función time.Time.Second() en Golang con ejemplos

En el lenguaje Go, los paquetes de tiempo brindan funcionalidad para determinar y ver el tiempo. La función Time.Second() en el lenguaje Go se usa para encontrar el segundo desplazamiento dentro del minuto proporcionado por «t» y el rango es [0, 59]. Además, esta función se define en el paquete de tiempo. Aquí, debe importar el paquete «tiempo» para usar estas funciones.

Sintaxis:

func (t Time) Second() int

Aquí, “t” es el tiempo indicado.

Valor devuelto: Devuelve el segundo desplazamiento dentro del minuto proporcionado por «t».

Ejemplo 1:

// Golang program to illustrate the usage of
// Time.Second() function
  
// Including main package
package main
  
// Importing fmt and time
import "fmt"
import "time"
  
// Calling main
func main() {
  
    // Declaring t in UTC
    t := time.Date(2017, 2, 3, 13, 
             12, 34, 50, time.UTC)
  
    // Calling Second method
    sec := t.Second()
  
    // Prints second as specified
    fmt.Printf("The stated second is: %v\n", sec)
}

Producción:

The stated second is: 34

Ejemplo 2:

// Golang program to illustrate the usage of
// Time.Second() function
  
// Including main package
package main
  
// Importing fmt and time
import "fmt"
import "time"
  
// Calling main
func main() {
  
    // Declaring t in UTC
    t := time.Date(2017, 2, 3, 13,
             12, 67, 50, time.UTC)
  
    // Calling Second method
    sec := t.Second()
  
    // Prints second as specified
    fmt.Printf("The stated second is: %v\n", sec)
}

Producción:

The stated second is: 7

Aquí, los segundos indicados en el código anterior están fuera del rango habitual, pero se normalizan durante la conversión.

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 *