Get the Current Unix Time

· 96 words · 1 minute read

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 an int or formatted into a readable string.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
package main

import (
    "fmt"
    "time"
)

func main() {
    currentTime := time.Now().Unix()
    fmt.Println("Current Unix Time:", currentTime)
}

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. He loves coding, but also enjoys cycling and camping in his spare time.

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!