belongs to collection: Golang syscall Package Programs
In the Go programming language, to get the number of seconds since the epoch using syscall – we use the Gettimeofday() function of the syscall package. The Gettimeofday() function returns the number of seconds and microseconds since the epoch.
Syntax:
func Gettimeofday(tv *Timeval) (err error)
Consider the below example demonstrating how to get the number of seconds since the epoch using syscall in Golang?
package main import ( "fmt" "syscall" "time" ) func main() { var TimeValue syscall.Timeval if err := syscall.Gettimeofday(&TimeValue); err != nil { fmt.Printf("Error: %v", err) } // Printing the seconds & micro seconds fmt.Println("Seconds: ", TimeValue.Sec) fmt.Println("Micro: ", TimeValue.Usec) // Calculate & Print the Current Date & Time // Using the seconds & micro seconds fmt.Println(time.Unix(TimeValue.Sec, TimeValue.Usec)) }
Output
Seconds: 1636704620 Micro: 779023 2021-11-12 08:10:20.000779023 +0000 UTC
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Syntax:
Consider the below example demonstrating how to get the number of seconds since the epoch using syscall in Golang?
Output
need an explanation for this answer? contact us directly to get an explanation for this answer