Get the Current Unix Time

· 85 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.

package main

import (

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!