Golang time.Unix() function example

package time

Golang time.Unix() function usage example

 package main

 import (
  "fmt"
  "os"
  "strconv"
  "time"
 )

 func main() {

  unixTimeStamp := "1432572732"  // generate with Unix/Linux command >date +%s

  unixIntValue, err := strconv.ParseInt(unixTimeStamp, 10, 64)

  if err != nil {
 fmt.Println(err)
 os.Exit(1)
  }

  timeStamp := time.Unix(unixIntValue, 0)

  fmt.Println(timeStamp)
 }

Output :

2015-05-25 16:52:12 +0000 UTC

Reference :

http://golang.org/pkg/time/#Unix

Advertisement