Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Unix Timestamp to Datetime in Go

How to convert Unix timestamp to Datetime in Go

🎈 🎈 🎈
+1

    package main

    import (
        "fmt"
        "time"
    )
    
    func main() {
        unixTimestamp := int64(399789333)
        dateTime := time.Unix(unixTimestamp, 0)
    
        fmt.Println("Converted Date:", dateTime)
    }
        

Output:
Converted Date: 1982-09-02 04:35:33
Example only. There may be multiple ways to perform this operation.

Code Explanation

In order to perform the Unix timestamp conversion in Go, the Unix timestamp '399789333' is passed to the time.Unix() function, which converts it to a time.Time object.
The second argument, 0, represents the nanoseconds (which is 0 in this case). The resulting time.Time object represents the corresponding date and time, which is then printed.



Other useful Go date functions

Function Description Example
time.Now() Returns the current date and time as a time.Time object. time.Now() returns 2024-08-28 12:34:56 +0000 UTC
time.Date() Creates a new time.Time object for a specific date and time. time.Date(2024, 8, 28, 12, 34, 56, 0, time.UTC) returns 2024-08-28 12:34:56 +0000 UTC
time.Unix() Converts a Unix timestamp (seconds since epoch) to a time.Time object. time.Unix(1698499452, 0) returns 2023-10-28 12:44:12 +0000 UTC
time.Parse() Parses a formatted string and returns the corresponding time.Time object. time.Parse("2006-01-02 15:04:05", "2024-08-28 12:34:56") returns 2024-08-28 12:34:56 +0000 UTC
time.Format() Formats a time.Time object into a string according to the specified layout. time.Now().Format("2006-01-02 15:04:05") returns 2024-08-28 12:34:56
time.Add() Adds a duration to a time.Time object, returning a new time.Time. time.Now().Add(24 * time.Hour) returns the same time tomorrow.
time.Sub() Subtracts one time.Time object from another, returning the duration between them. time.Now().Sub(pastTime) returns the duration since pastTime.
time.Since() Returns the duration since the specified time.Time. time.Since(startTime) returns the duration since startTime.
time.Sleep() Pauses the current goroutine for at least the specified duration. time.Sleep(2 * time.Second) pauses for 2 seconds.
time.UTC() Returns a time.Time object corresponding to the specified UTC time. time.UTC(2024, 8, 28, 12, 34, 56, 0) returns 2024-08-28 12:34:56 +0000 UTC
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder