Welcome To Golang By Example

Menu
  • Home
  • Blog
Menu

Convert Unix TimeStamp to time.Time in Go (Golang)

Posted on February 1, 2023February 1, 2023 by admin

Time can be represented in GO in both time.Time and Unix Timestamp format. The Unix Timestamp also known as Epoch Time is the number of seconds elapsed since 00:00:00 UTC on 1 January 1970. This time is also known as the Unix epoch. Below code shows the conversion of

  • time.Time to Unix Timestamp
  • Unix Timestamp to time.Time
package main
import (
"fmt"
"time"
)
func main() {
tNow := time.Now()
//time.Time to Unix Timestamp
tUnix := tNow.Unix()
fmt.Printf("timeUnix %d\n", tUnix)
//Unix Timestamp to time.Time
timeT := time.Unix(tUnix, 0)
fmt.Printf("time.Time: %s\n", timeT)
}

Output:

timeUnix 1257894000
time.Time: 2009-11-10 23:00:00 +0000 UTC
  • time.Time
  • unix
  • Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2023 Welcome To Golang By Example | Design: Web XP