Menu Close

Go – How to get current unix timestamp in go

We will learn how to get current unix timestamp in go. We will learn it by program and Unix() function in time package in go.

Unix() function is used to get the local Time corresponding to the given Unix time, seconds and nanoseconds since January 1, 1970 UTC.

Function prototype:

func Unix(sec int64, nsec int64) Time

Return value:

Unix() function in time package returns 
local Time corresponding to the given Unix 
time, seconds and nanoseconds since 
January 1, 1970 UTC.

Example with code:

package main

import (

  "fmt"
  "time"
)

func main() {


  curr_time := time.Now().Unix()

  fmt.Println("Current time:  ", curr_time)
}

Output:

Current time: 1590670357

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, time

Leave a Reply

Your email address will not be published. Required fields are marked *