A practical, expert-written guide that shows how to convert time to epoch time across tools and languages, with clear steps, examples, pitfalls, and best practices.
If you need to convert time to epoch time for logging, APIs, databases, or automation, this guide is for you. We explain epoch time in plain language and show you fast, reliable ways to do it in Python, JavaScript, SQL, Excel, and more. You’ll also learn timezone and DST pitfalls, and best practices for clean, accurate conversions.
Featured Snippet (60 words): To convert time to epoch time, normalize your date to UTC, parse it with a reliable library or system tool, and output seconds (or milliseconds) since 1970-01-01 00:00:00 UTC. Common steps: choose timezone, parse input, adjust to UTC, compute Unix timestamp, verify. Use built-in functions like Python datetime, JavaScript Date, or a trusted online converter.
Epoch time (Unix timestamp) counts seconds from 1970-01-01 00:00:00 UTC. It’s compact, unambiguous, and ideal for logs, APIs, and cross-language systems. To convert time to epoch time, parse your local or specified datetime, shift to UTC, and compute seconds (or milliseconds) since the epoch. Watch for timezones, DST, and units (s vs ms). Use built-in functions in Python, JS, SQL, or a trusted tool like ZenixTools.
Epoch time, also called a Unix timestamp, is a single number that represents a moment in time. It counts the seconds (or milliseconds) since 1970-01-01 00:00:00 Coordinated Universal Time (UTC). Because it is just a number, it is easy to sort, compare, store, and exchange across systems.
Key points:
To 'convert time to epoch time' means to take a human-readable date and time (for example, 2026-05-21 14:30 in New York) and convert it into the numeric count of seconds or milliseconds since the Unix epoch in UTC. This process requires knowing (or assuming) the correct timezone and then normalizing to UTC before creating the final number.
Follow these steps to get accurate results every time.
Shortcuts with common tools:
Below are practical conversions across languages and tools. Each example converts a known time to epoch and highlights timezone handling.
from datetime import datetime, timezone
import zoneinfo # Python 3.9+
# Example: 2026-08-19 14:30 in New York
ny_tz = zoneinfo.ZoneInfo('America/New_York')
dt_local = datetime(2026, 8, 19, 14, 30, 0, tzinfo=ny_tz)
# Convert to UTC
dt_utc = dt_local.astimezone(timezone.utc)
# Seconds since epoch
epoch_seconds = int(dt_utc.timestamp())
# Milliseconds since epoch
epoch_millis = int(dt_utc.timestamp() * 1000)
print(epoch_seconds, epoch_millis)
// ISO with timezone offset is safest
const dt = new Date('2026-08-19T14:30:00-04:00');
// Milliseconds since epoch
const ms = dt.getTime();
// Seconds since epoch
const s = Math.floor(ms / 1000);
console.log(s, ms);
// If you only have local parts, build with UTC to avoid surprises
const utc = Date.UTC(2026, 7, 19, 18, 30, 0); // month is 0-based; 7=August
console.log(Math.floor(utc / 1000));
const { DateTime } = require('luxon');
const dt = DateTime.fromISO('2026-08-19T14:30:00', { zone: 'America/New_York' });
const epochSeconds = Math.floor(dt.toUTC().toSeconds());
console.log(epochSeconds);
# Local time to epoch (seconds)
date -d '2026-08-19 14:30' +%s
# Specific timezone (TZ env)
TZ='America/New_York' date -d '2026-08-19 14:30' +%s
# ISO 8601 with offset is safest
date -d '2026-08-19T14:30:00-04:00' +%s
# Local time to epoch seconds
$dt = Get-Date '2026-08-19 14:30:00'
$epoch = [int][double]::Floor((Get-Date -Date $dt.ToUniversalTime() -UFormat %s))
$epoch
# Or using .NET
$unixEpoch = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
using System;
var tz = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
var local = new DateTime(2026, 8, 19, 14, 30, 0, DateTimeKind.Unspecified);
var zoned = TimeZoneInfo.ConvertTimeToUtc(local, tz);
long epochSeconds = new DateTimeOffset(zoned).ToUnixTimeSeconds();
Console.WriteLine(epochSeconds);
import java.time.*;
import java.time.format.DateTimeFormatter;
ZoneId zone = ZoneId.of("America/New_York");
LocalDateTime local = LocalDateTime.parse("2026-08-19T14:30:00");
ZonedDateTime zoned = local.atZone(zone);
long epochSeconds = zoned.toEpochSecond();
System.out.println(epochSeconds);
package main
import (
"fmt"
"time"
)
func main() {
loc, _ := time.LoadLocation("America/New_York")
t := time.Date(2026, 8, 19, 14, 30, 0, 0, loc)
fmt.Println(t.Unix()) // seconds
fmt.Println(t.UnixMilli()) // milliseconds
}
-- Assume '2026-08-19 14:30' in America/New_York
SET TIME ZONE 'America/New_York';
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2026-08-19 14:30:00');
-- With timestamptz and UTC
SELECT EXTRACT(EPOCH FROM TIMESTAMPTZ '2026-08-19 14:30:00-04');
-- Convert a timestamp in a named timezone to epoch seconds
SELECT UNIX_TIMESTAMP(CONVERT_TZ('2026-08-19 14:30:00','America/New_York','UTC'));
=(A1 - DATE(1970,1,1)) * 86400
Many APIs return or accept epoch milliseconds. For example, JavaScript front ends often send Date.now(). Always check the API docs for unit expectations.
| Method/Language | Timezone Handling | Default Unit | Pros | Cons |
|---|---|---|---|---|
| ZenixTools Converter | Excellent (explicit TZ) | Seconds or ms | Fast, no code, human-friendly | Requires internet |
| Python datetime/zoneinfo | Excellent | Seconds | Strong TZ support, readable | Requires imports and care with naive datetimes |
| JavaScript Date | Good with ISO inputs | Milliseconds | Built-in everywhere | Local vs UTC confusion, month indexing quirks |
| Java java.time | Excellent | Seconds | Modern, safe, immutable | Verbose for newcomers |
| Postgres EXTRACT(EPOCH) | Excellent | Seconds | Native SQL, robust | DB-specific syntax |
| MySQL UNIX_TIMESTAMP | Good | Seconds | Simple, common | Named TZ support requires CONVERT_TZ |
Epoch time gives you a simple, reliable way to represent any moment as a single number. When you convert time to epoch time, identify the timezone, normalize to UTC, choose the right unit (seconds or milliseconds), and validate the result. With these steps, your timestamps will be accurate, portable, and ready for any system.
Need a fast, accurate conversion right now? Use the free ZenixTools Unix Timestamp Converter to convert time to epoch time in seconds or milliseconds. Paste your date, pick a timezone, and copy the result in one click. Save time, reduce errors, and standardize your workflow today.
Learn how to convert 1 meter to feet with precise formulas, quick methods, and real-world examples. Includes best practices, common mistakes, comparison tables, FAQs, and expert tips for accurate length conversions.
Learn how to convert 1 meter to feet with the exact formula, step-by-step instructions, quick mental math, and real-world examples. Includes charts, best practices, FAQs, and expert tips.
| Bash date | Good | Seconds | Fast on Linux, scripting | Platform differences (BSD vs GNU) |
| Excel/Sheets | Poor to Fair | Seconds (via formula) | Ubiquitous | Timezone handling is manual |