En el lenguaje Go, los paquetes de tiempo brindan funcionalidad para determinar y ver el tiempo. La función Milliseconds() en el lenguaje Go se usa para encontrar la duración del tiempo en forma de un conteo de milisegundos entero. Además, esta función se define en el paquete de tiempo. Aquí, debe importar el paquete «tiempo» para usar estas funciones.
Sintaxis:
func (d Duration) Milliseconds() int64
Aquí, d es la duración del tiempo.
Valor devuelto: Devuelve el valor de duración como int64.
Ejemplo 1:
// Golang program to illustrate the usage of // Milliseconds() function // Including main package package main // Importing fmt and time import ( "fmt" "time" ) // Calling main func main() { // Defining duration // of Milliseconds method milli, _ := time.ParseDuration("7s") // Prints duration as // an integer milliseconds fmt.Printf("Only %d milliseconds of "+ "task is remaining.", milli.Milliseconds()) }
Producción:
Only 7000 milliseconds of task is remaining.
Ejemplo 2:
// Golang program to illustrate the usage of // Milliseconds() function // Including main package package main // Importing fmt and time import ( "fmt" "time" ) // Calling main func main() { // Defining duration of // Milliseconds method milli, _ := time.ParseDuration("2h1m2s4545ns") // Prints duration as // an integer milliseconds fmt.Printf("Only %d milliseconds of"+ " task is remaining.", milli.Milliseconds()) }
Producción:
Only 7262000 milliseconds of task is remaining.
Publicación traducida automáticamente
Artículo escrito por nidhi1352singh y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA