Programming

How to Convert Epoch Time: Complete Guide to Unix Time Conversion

Learn how to convert epoch time to date and date to Unix timestamp. Complete guide with examples in JavaScript, Python, and more programming languages.

January 8, 2024
8 min read

How to Convert Epoch Time: Complete Guide to Unix Time Conversion

Converting epoch time (Unix timestamps) is one of the most common tasks in programming. Whether you're working with APIs, databases, or log files, understanding how to convert between Unix timestamps and human-readable dates is essential.

What is Epoch Time?

Epoch time, also known as Unix time or POSIX time, represents the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. This standardized format makes it easy to store and compare dates across different systems and time zones.

Converting Epoch Time to Date

JavaScript

// Convert Unix timestamp to date const timestamp = 1727280000; const date = new Date(timestamp * 1000); // Multiply by 1000 for milliseconds // Format the date console.log(date.toLocaleString()); // "9/25/2024, 12:00:00 PM" console.log(date.toISOString()); // "2024-09-25T12:00:00.000Z" // Custom formatting const options = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', timeZoneName: 'short' }; console.log(date.toLocaleString('en-US', options)); // "September 25, 2024 at 12:00:00 PM UTC"

Python

import datetime # Convert Unix timestamp to date timestamp = 1727280000 date = datetime.datetime.fromtimestamp(timestamp) # Format the date print(date.strftime('%Y-%m-%d %H:%M:%S')) # "2024-09-25 12:00:00" print(date.strftime('%B %d, %Y at %I:%M %p')) # "September 25, 2024 at 12:00 PM" # UTC conversion utc_date = datetime.datetime.utcfromtimestamp(timestamp) print(utc_date.strftime('%Y-%m-%d %H:%M:%S UTC')) # "2024-09-25 12:00:00 UTC"

Need a quick conversion? Try our Unix timestamp converter for instant results, or use our batch converter to convert multiple timestamps at once!

Try Our Unix Timestamp Converter Tools

Put your new knowledge to practice with our interactive timestamp conversion tools.