Epoch To Unix Timestamp Conversion

Last updated on September 1st, 2023 at 07:37 pm

Epoch Converter

Enter an epoch timestamp:

UTC Time:

Enter a date and time (UTC):

Epoch Timestamp:

Python

import datetime
epoch_timestamp = 1629733254  # Replace with your epoch timestamp
utc_time = datetime.datetime.utcfromtimestamp(epoch_timestamp)
print(utc_time)

Java

import java.util.Date;

long epochTimestamp = 1629733254L;  // Replace with your epoch timestamp
Date utcDate = new Date(epochTimestamp * 1000);  // Java works with milliseconds
System.out.println(utcDate);

JavaScript

const epochTimestamp = 1629733254;  // Replace with your epoch timestamp
const utcDate = new Date(epochTimestamp * 1000);  // JavaScript works with milliseconds
console.log(utcDate.toUTCString());

C++

#include <iostream>
#include <ctime>

int main() {
    time_t epochTimestamp = 1629733254;  // Replace with your epoch timestamp
    struct tm* utcTime = gmtime(&epochTimestamp);
    std::cout << asctime(utcTime);
    return 0;
}

Ruby

epoch_timestamp = 1629733254  # Replace with your epoch timestamp
utc_time = Time.at(epoch_timestamp).utc
puts utc_time

PHP

$epochTimestamp = 1629733254;  // Replace with your epoch timestamp
$utcTime = gmdate("Y-m-d H:i:s", $epochTimestamp);
echo $utcTime;

C#

using System;

class Program
{
    static void Main()
    {
        long epochTimestamp = 1629733254;  // Replace with your epoch timestamp
        DateTimeOffset utcTime = DateTimeOffset.FromUnixTimeSeconds(epochTimestamp);
        Console.WriteLine(utcTime);
    }
}

Swift

import Foundation

let epochTimestamp = 1629733254  // Replace with your epoch timestamp
let utcDate = Date(timeIntervalSince1970: TimeInterval(epochTimestamp))
print(utcDate)

Kotlin

import java.util.*

fun main() {
    val epochTimestamp = 1629733254L  // Replace with your epoch timestamp
    val utcDate = Date(epochTimestamp * 1000)  // Kotlin works with milliseconds
    println(utcDate)
}

Go ( GoLang )

package main

import (
    "fmt"
    "time"
)

func main() {
    epochTimestamp := int64(1629733254)  // Replace with your epoch timestamp
    utcTime := time.Unix(epochTimestamp, 0).UTC()
    fmt.Println(utcTime)
}

MATLAB

epochTimestamp = 1629733254;  % Replace with your epoch timestamp
utcTime = datetime(epochTimestamp, 'ConvertFrom', 'posixtime', 'TimeZone', 'UTC');
disp(utcTime);

Scala

import java.util.Date

object EpochToUTC {
  def main(args: Array[String]): Unit = {
    val epochTimestamp = 1629733254L  // Replace with your epoch timestamp
    val utcDate = new Date(epochTimestamp * 1000L)  // Scala works with milliseconds
    println(utcDate)
  }
}

Lua

epochTimestamp = 1629733254  -- Replace with your epoch timestamp
utcTime = os.date("!%Y-%m-%d %H:%M:%S", epochTimestamp)
print(utcTime)

Perl

my $epochTimestamp = 1629733254;  # Replace with your epoch timestamp
my $utcTime = gmtime($epochTimestamp);
print $utcTime;

Rust

use std::time::{SystemTime, UNIX_EPOCH};

fn main() {
    let epochTimestamp = 1629733254;  // Replace with your epoch timestamp
    let duration = std::time::Duration::from_secs(epochTimestamp as u64);
    let utcTime = UNIX_EPOCH + duration;
    println!("{:?}", utcTime);
}

Haskell

import Data.Time.Clock.POSIX
import Data.Time.Clock

main :: IO ()
main = do
    let epochTimestamp = 1629733254  -- Replace with your epoch timestamp
    let utcTime = posixSecondsToUTCTime (fromIntegral epochTimestamp)
    print utcTime

SQL

SELECT TO_TIMESTAMP(1629733254)::timestamp AT TIME ZONE 'UTC';

Leave a Reply