Golang Code

Get Unix Time

· 86 words · 1 minute read #format #nanosecond #now #print #strconv #time #unix

This is a simple way to get the current system time in the unix format and in this example we’re just printing the result to screen. This is all accessible from the time package. The Unix() function will actually return a type of Time (which is the stored time to the nanosecond) - but this can be converted into and int or formatted into a readable string.

package main

import (
    "fmt"
    "time"
)

func main() {
    time := time.Now().Unix()
    fmt.Printf("Current Unix Time: %v\n", time)
}
Image of Author Edd Turtle

Author: Edd Turtle

Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-ready Go and PHP code.

See something which isn't right? You can contribute to this page on GitHub or just let us know in the comments below. Thanks for reading!