在 Go 语言中,时间包提供了确定和查看时间的功能。 Go 语言中的Microseconds()函数用于以整数微秒计数的形式查找持续时间。而且,这个函数是在time包下定义的。在这里,您需要导入“time”包才能使用这些功能。
句法:
func (d Duration) Microseconds() int64
这里,d 是持续时间。
返回值:它将持续时间值返回为 int64。
示例 1:
// Golang program to illustrate the usage of
// Microseconds() function
// Including main package
package main
// Importing fmt and time
import (
"fmt"
"time"
)
// Calling main
func main() {
// Defining duration
// of Microseconds method
micr, _ := time.ParseDuration("5m")
// Prints duration as
// an integer microsecond
fmt.Printf("Only %d Microseconds of task "+
"is remaining.", micr.Microseconds())
}
输出:
Only 300000000 Microseconds of task is remaining.
示例 2:
// Golang program to illustrate the usage of
// Microseconds() function
// Including main package
package main
// Importing fmt and time
import (
"fmt"
"time"
)
// Calling main
func main() {
// Defining duration of Microseconds method
micr, _ := time.ParseDuration("1m1s576ms46ns")
// Prints duration as
// an integer microsecond
fmt.Printf("Only %d Microseconds of "+
"task is remaining.", micr.Microseconds())
}
输出:
Only 61576000 Microseconds of task is remaining.