Epoch Converter - Unix Timestamp Converter

Now (Unix timestamp):

What Is Epoch Time — And Why You Should Care

Epoch time (also called Unix time or POSIX time) is the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC — the “epoch.” It’s a simple, universal way to represent points in time as a single number.

Why Does Epoch Time Exist?

The problem it solves is consistency and precision in handling dates and times across systems, languages, and platforms.

Think about this: dates and times can be stored in hundreds of different formats, depending on database, locale, or language. Some use strings like “2025-07-19 14:30:00”, others store separate year/month/day columns, and many formats vary wildly across regions (DD/MM/YYYY vs MM/DD/YYYY).

This creates chaos:

  • Parsing errors
  • Timezone bugs
  • Inconsistent date math
  • Hard-to-maintain code
  • And worst of all — wrong data

Why Not Store Dates As Readable Text?

Yes, humans prefer readable dates. But computers don’t care about readability — they care about efficiency, accuracy, and interoperability. Epoch time is:

  • Unambiguous: Always the same format worldwide
  • Compact: A single integer fits everywhere, from databases to APIs
  • Easy to compare: You can subtract one epoch from another to get elapsed time instantly
  • Timezone agnostic: The number always represents the same instant, regardless of locale

The Hidden Cost of Ignoring Epoch

Developers who store dates as strings or in complex formats risk all sorts of problems down the line:

  • Timezone conversion bugs that cause incorrect timestamps
  • Complicated date math slowing down applications
  • Migration headaches when moving between systems
  • Performance overhead from parsing and formatting text dates

Epoch time cuts through all that mess with a simple number. Once you adopt it, your code becomes cleaner, faster, and far less error-prone.


In short: using epoch time is not just a “nice to have” — it’s a must for any serious developer building reliable, scalable software.

Convert Unix epoch to human-readable date in Python

import datetime

def epoch_to_human_readable(epoch_time):
    # Convert seconds since epoch to human-readable date in ISO 8601 UTC
    dt = datetime.datetime.utcfromtimestamp(epoch_time)
    return dt.isoformat() + "Z"

# Example usage
print(epoch_to_human_readable(1672531200))

Get current Unix timestamp in Python

import time

def get_current_unix_timestamp():
    return int(time.time())

# Example usage
print(get_current_unix_timestamp())

How to turn a date into a Unix epoch timestamp with Python?

import datetime

def date_to_epoch(date_str, date_format="%Y-%m-%d %H:%M:%S"):
    dt = datetime.datetime.strptime(date_str, date_format)
    return int(dt.timestamp())

# Example usage
print(date_to_epoch("2023-12-31 00:00:00"))

Calculate difference between two epoch times in Python

def epoch_difference(epoch1, epoch2):
    diff_seconds = abs(epoch2 - epoch1)
    return diff_seconds

# Example usage
print(epoch_difference(1672531200, 1672617600))  # difference in seconds

Convert milliseconds to seconds (and vice versa) for epoch in Python

def ms_to_seconds(milliseconds):
    return milliseconds / 1000

def seconds_to_ms(seconds):
    return int(seconds * 1000)

# Example usage
print(ms_to_seconds(1650000000000))  # Convert ms to seconds
print(seconds_to_ms(1650000000))     # Convert seconds to ms

Change epoch timestamp timezone in Python (including custom offsets)

import datetime
import pytz

def convert_epoch_timezone(epoch_time, from_tz='UTC', to_tz='America/New_York'):
    from_zone = pytz.timezone(from_tz)
    to_zone = pytz.timezone(to_tz)
    utc_time = datetime.datetime.utcfromtimestamp(epoch_time).replace(tzinfo=pytz.utc)
    from_time = utc_time.astimezone(from_zone)
    to_time = from_time.astimezone(to_zone)
    return to_time.isoformat()

# Example usage
print(convert_epoch_timezone(1672531200, 'UTC', 'Asia/Tokyo'))

Add or subtract days/hours/minutes from epoch time in Python

import datetime

def add_subtract_time(epoch_time, days=0, hours=0, minutes=0):
    dt = datetime.datetime.utcfromtimestamp(epoch_time)
    delta = datetime.timedelta(days=days, hours=hours, minutes=minutes)
    new_dt = dt + delta
    return int(new_dt.timestamp())

# Example usage
print(add_subtract_time(1672531200, days=1, hours=-2, minutes=30))

Check if a number is a valid epoch timestamp in Python

import datetime

def is_valid_epoch(epoch_time):
    try:
        # Check if timestamp can convert to a datetime
        datetime.datetime.utcfromtimestamp(epoch_time)
        return True
    except (OverflowError, OSError, ValueError):
        return False

# Example usage
print(is_valid_epoch(1672531200))  # True
print(is_valid_epoch(-99999999999))  # False or raises error depending on platform

Parse date string into epoch timestamp using Python

import datetime

def parse_date_to_epoch(date_string, date_format="%Y-%m-%d %H:%M:%S"):
    dt = datetime.datetime.strptime(date_string, date_format)
    return int(dt.timestamp())

# Example usage
print(parse_date_to_epoch("2023-07-15 12:00:00"))

Parse date string into epoch timestamp using Python

from datetime import datetime

date_str = "2025-07-19 14:30:00"
dt = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
epoch_time = int(dt.timestamp())
print(epoch_time)

Format epoch time to YYYY-MM-DD or custom format in Python

from datetime import datetime

epoch_time = 1750657800  # example epoch
dt = datetime.fromtimestamp(epoch_time)
formatted_date = dt.strftime("%Y-%m-%d")  # Custom format example: "YYYY-MM-DD"
print(formatted_date)

# Example of custom format:
custom_format = dt.strftime("%d/%m/%Y %I:%M %p")
print(custom_format)

Convert epoch timestamp to local date/time string in Python

from datetime import datetime

epoch_time = 1750657800  # example epoch
local_dt = datetime.fromtimestamp(epoch_time)
local_dt_str = local_dt.strftime("%Y-%m-%d %H:%M:%S")
print(local_dt_str)

Convert epoch timestamp to Julian date in Python

from datetime import datetime
import math

def epoch_to_julian_date(epoch):
    dt = datetime.utcfromtimestamp(epoch)
    # Algorithm from https://aa.usno.navy.mil/faq/julian-date-conversion
    year = dt.year
    month = dt.month
    day = dt.day + dt.hour/24 + dt.minute/(24*60) + dt.second/(24*3600)
    if month <= 2:
        year -= 1
        month += 12
    A = math.floor(year / 100)
    B = 2 - A + math.floor(A / 4)
    JD = math.floor(365.25 * (year + 4716)) + math.floor(30.6001 * (month + 1)) + day + B - 1524.5
    return JD

epoch_time = 1750657800  # example epoch
julian_date = epoch_to_julian_date(epoch_time)
print(julian_date)

Find week number from epoch time in Python

from datetime import datetime

epoch_time = 1750657800  # example epoch
dt = datetime.fromtimestamp(epoch_time)
week_number = dt.isocalendar()[1]  # ISO week number
print(week_number)

Get day of the week from epoch timestamp in Python

from datetime import datetime

epoch_time = 1750657800  # example epoch
dt = datetime.fromtimestamp(epoch_time)
# weekday() returns 0=Monday, 6=Sunday
day_of_week_num = dt.weekday()
# Get full weekday name
day_of_week_name = dt.strftime("%A")
print(day_of_week_num, day_of_week_name)

Show elapsed time between two epoch timestamps in a readable way using Python

def format_elapsed_time(seconds):
    minutes, sec = divmod(seconds, 60)
    hours, minutes = divmod(minutes, 60)
    days, hours = divmod(hours, 24)
    parts = []
    if days > 0:
        parts.append(f"{days} days")
    if hours > 0:
        parts.append(f"{hours} hours")
    if minutes > 0:
        parts.append(f"{minutes} minutes")
    if sec > 0:
        parts.append(f"{sec} seconds")
    return ", ".join(parts)

epoch_start = 1750650000
epoch_end = 1750657800
elapsed_sec = epoch_end - epoch_start
print(format_elapsed_time(elapsed_sec))

In Java, how can you convert a Unix‑epoch integer into a human‑readable date string (for example, ISO 8601 or UTC)?


import java.time.Instant;
public class EpochToIso {
  public static void main(String[] args) {
    long epochSec = 962392935L;
    String iso = Instant.ofEpochSecond(epochSec).toString();
    System.out.println(iso);  // 2000-06-30T19:22:15Z
  }
}

Using Java, what’s the process to transform a formatted calendar date back into its Unix‑epoch equivalent?


import java.time.LocalDate;
import java.time.ZoneOffset;
public class DateToEpoch {
  public static void main(String[] args) {
    LocalDate date = LocalDate.parse("2025-07-20");
    long epochSec = date.atStartOfDay().toEpochSecond(ZoneOffset.UTC);
    System.out.println(epochSec);
  }
}

How do you obtain the current Unix‑epoch timestamp within a Java application?


import java.time.Instant;
public class NowEpoch {
  public static void main(String[] args) {
    long sec = Instant.now().getEpochSecond();
    long millis = Instant.now().toEpochMilli();
    System.out.println("Seconds: " + sec);
    System.out.println("Milliseconds: " + millis);
  }
}

In Java code, how can you calculate the interval between two epoch timestamps?


import java.time.Duration;
import java.time.Instant;
public class EpochDifference {
  public static void main(String[] args) {
    Instant a = Instant.now();
    Instant b = a.plusSeconds(3600);
    Duration d = Duration.between(a, b);
    System.out.println("Difference in seconds: " + d.getSeconds());
  }
}

What’s the Java approach for switching an epoch value between milliseconds and seconds?


public class EpochMsSec {
  public static void main(String[] args) {
    long ms = 1_632_345_678_901L;
    long sec = ms / 1000L;
    long backToMs = sec * 1000L;
    System.out.println(ms + " → " + sec + " → " + backToMs);
  }
}

How do you translate epoch timestamps across different time zones in Java, including custom UTC offsets?


import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class EpochTZ {
  public static void main(String[] args) {
    long epochMs = 1_653_109_390_070L;
    Instant i = Instant.ofEpochMilli(epochMs);
    ZonedDateTime utc = i.atZone(ZoneOffset.UTC);
    ZonedDateTime plus530 = i.atZone(ZoneOffset.ofHoursMinutes(5, 30));
    System.out.println(DateTimeFormatter.ISO_INSTANT.format(utc));
    System.out.println(plus530);
  }
}

In Java, how can you add or subtract days, hours, or minutes from a given epoch timestamp?


import java.time.Instant;
import java.time.Duration;
public class EpochAddSubtract {
  public static void main(String[] args) {
    Instant now = Instant.now();
    Instant later = now.plus(Duration.ofHours(5).plusMinutes(30));
    Instant earlier = now.minus(Duration.ofDays(2));
    System.out.println("Now: " + now);
    System.out.println("Later: " + later);
    System.out.println("Earlier: " + earlier);
  }
}

What Java logic would you use to verify whether a number represents a valid epoch timestamp?


import java.time.Instant;
import java.time.DateTimeException;

public class EpochValidator {
    public static boolean isValidEpoch(long epochSec) {
        try {
            Instant.ofEpochSecond(epochSec);
            return true;
        } catch (DateTimeException ex) {
            return false;
        }
    }
}

Using Java, how do you parse a date‐formatted string and extract its epoch timestamp?


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.ZoneOffset;

public class DateParser {
    public static long parseToEpoch(String dateStr) {
        LocalDateTime dt = LocalDateTime.parse(dateStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        return dt.toEpochSecond(ZoneOffset.UTC);
    }
}

How can you format an epoch timestamp into a specific pattern (e.g. “YYYY-MM-DD”) in Java?


import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class EpochFormatter {
    public static String formatDate(long epochSec) {
        return Instant.ofEpochSecond(epochSec)
                      .atZone(ZoneId.of("UTC"))
                      .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
}

In Java, what’s the best way to convert an epoch timestamp into a localized date/time string?


import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class LocalizedFormatter {
    public static String toLocalDateTime(long epochSec) {
        ZonedDateTime zdt = Instant.ofEpochSecond(epochSec)
                                   .atZone(ZoneId.systemDefault());
        return zdt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}

How do you convert an epoch timestamp to a Julian date using Java?


public class JulianDateConverter {
    public static double toJulianDate(long epochSec) {
        // Julian Date for Unix epoch (1970-01-01T00:00:00Z) is 2440587.5
        return epochSec / 86400.0 + 2440587.5;
    }
}

In Java, how would you compute the ISO week number for a given epoch value?


import java.time.Instant;
import java.time.ZoneOffset;
import java.time.temporal.WeekFields;
import java.util.Locale;

public class WeekNumberCalculator {
    public static int getIsoWeek(long epochSec) {
        return Instant.ofEpochSecond(epochSec)
                      .atZone(ZoneOffset.UTC)
                      .get(WeekFields.ISO.weekOfWeekBasedYear());
    }
}

How can Java determine the day of the week corresponding to an epoch timestamp?


import java.time.Instant;
import java.time.ZoneOffset;
import java.time.DayOfWeek;

public class DayOfWeekFinder {
    public static DayOfWeek getDay(long epochSec) {
        return Instant.ofEpochSecond(epochSec)
                      .atZone(ZoneOffset.UTC)
                      .getDayOfWeek();
    }
}

Using Java, how do you express the duration between two epoch timestamps in a human-friendly format?


import java.time.Duration;
import java.time.Instant;

public class DurationFormatter {
    public static String humanDuration(long startEpoch, long endEpoch) {
        Duration d = Duration.between(
            Instant.ofEpochSecond(startEpoch),
            Instant.ofEpochSecond(endEpoch)
        );
        long days = d.toDays();
        long hours = d.toHours() % 24;
        long mins = d.toMinutes() % 60;
        long secs = d.getSeconds() % 60;
        return String.format("%d days, %d hours, %d minutes, %d seconds",
                             days, hours, mins, secs);
    }
}

How do I convert a Unix epoch timestamp to a human‑readable date string in JavaScript (e.g. ISO 8601, UTC)?

const epochMs = 1625097600000;
const iso = new Date(epochMs).toISOString();   // ISO 8601
const utc = new Date(epochMs).toUTCString();   // UTC string
console.log(iso, utc);

What’s the JavaScript method for turning a formatted date into its Unix epoch equivalent?

const epochMs = new Date('2025-07-20T15:30:00').getTime();
console.log(epochMs);

How can I fetch the current Unix epoch timestamp in JavaScript?

const nowMs = Date.now();
const nowSec = Math.floor(nowMs / 1000);
console.log(nowMs, nowSec);

In JavaScript, how do you compute the difference between two epoch timestamps?

const diffMs = endEpochMs - startEpochMs;
const diffSec = Math.floor(diffMs / 1000);
console.log(diffMs, diffSec);

What’s the easiest way in JavaScript to switch epoch values between milliseconds and seconds?

const sec = ms / 1000;
const backToMs = sec * 1000;
console.log(sec, backToMs);

How do you adjust a Unix epoch timestamp for different time zones in JavaScript, including custom UTC offsets?

const offsetHours = 5.5; // UTC+5:30
const localMs = epochMs + offsetHours * 3600 * 1000;
console.log(new Date(localMs).toString());

Using JavaScript, how can I add or subtract days, hours, or minutes from a given epoch timestamp?

// To add:
const newEpochAdd = epochMs + (days * 86400 + hours * 3600 + minutes * 60) * 1000;
// To subtract:
const newEpochSub = epochMs - (days * 86400 + hours * 3600 + minutes * 60) * 1000;
console.log(new Date(newEpochAdd), new Date(newEpochSub));

How do I convert a Unix epoch timestamp to a human‑readable date string in JavaScript (e.g. ISO 8601, UTC)?

const epochMs = 1625097600000;
const iso = new Date(epochMs).toISOString();   // ISO 8601
const utc = new Date(epochMs).toUTCString();   // UTC string
console.log(iso, utc);

What’s the JavaScript method for turning a formatted date into its Unix epoch equivalent?

const epochMs = new Date('2025-07-20T15:30:00').getTime();
console.log(epochMs);

How can I fetch the current Unix epoch timestamp in JavaScript?

const nowMs = Date.now();
const nowSec = Math.floor(nowMs / 1000);
console.log(nowMs, nowSec);

In JavaScript, how do you compute the difference between two epoch timestamps?

const diffMs = endEpochMs - startEpochMs;
const diffSec = Math.floor(diffMs / 1000);
console.log(diffMs, diffSec);

What’s the easiest way in JavaScript to switch epoch values between milliseconds and seconds?

const sec = ms / 1000;
const backToMs = sec * 1000;
console.log(sec, backToMs);

How do you adjust a Unix epoch timestamp for different time zones in JavaScript, including custom UTC offsets?

const offsetHours = 5.5; // UTC+5:30
const localMs = epochMs + offsetHours * 3600 * 1000;
console.log(new Date(localMs).toString());

Using JavaScript, how can I add or subtract days, hours, or minutes from a given epoch timestamp?

// To add:
const newEpochAdd = epochMs + (days * 86400 + hours * 3600 + minutes * 60) * 1000;
// To subtract:
const newEpochSub = epochMs - (days * 86400 + hours * 3600 + minutes * 60) * 1000;
console.log(new Date(newEpochAdd), new Date(newEpochSub));

This table compares how different databases handle and convert Unix epoch timestamps into human-readable date formats. It includes relational databases (PostgreSQL, MySQL, SQL Server), NoSQL systems (MongoDB, DynamoDB), cloud data warehouses (BigQuery, Snowflake), and time-series databases (InfluxDB, Timestream).

For each database, you'll find:

  • Type: Relational, document, time-series, etc.
  • Notes: Logging suitability, timestamp support, and limitations
  • Epoch Conversion: SQL queries or methods to convert epoch to date and vice versa

This is especially useful when working directly in tools like Aqua Data Studio, DBeaver, or native SQL shells to interpret logs or event timestamps.


Database Type Notes Epoch Conversion SQL / Method
PostgreSQL Relational / Time-series (via TimescaleDB) Extensible, full-featured SQL, strong timestamp support TO_TIMESTAMP(epoch) or EXTRACT(EPOCH FROM timestamp)
MySQL / MariaDB Relational Not optimized for massive event ingestion FROM_UNIXTIME(epoch) or UNIX_TIMESTAMP(datetime)
Microsoft SQL Server Relational Limited native support for Unix time DATEADD(SECOND, epoch, '1970-01-01')
MongoDB NoSQL Document JSON logs fit well; conversion in app layer or aggregation pipeline Stores dates as ISODate (which is epoch milliseconds under the hood); convert in code or aggregation with $toDate
Amazon DynamoDB NoSQL Key-Value / Document No built-in date ops — convert epoch in app or Lambda layer Use epoch as numeric field; convert in code (e.g., JS: new Date(epoch * 1000))
Google BigQuery (GBQ) Cloud Columnar Cheap, blazing fast SQL on massive data TIMESTAMP_SECONDS(epoch) or UNIX_SECONDS(timestamp)
ClickHouse Columnar OLAP Extremely fast ingestion & queries FROM_UNIXTIME(epoch) or toUnixTimestamp(datetime)
Snowflake Cloud Data Warehouse Costly for high-frequency writes DATEADD(SECOND, epoch, '1970-01-01')
Azure Data Explorer (Kusto) Time-Series + Analytics Used in Azure Monitor and Log Analytics unixtime_seconds_todatetime(epoch) or unixtime_milliseconds_todatetime()
Elasticsearch / OpenSearch Search Engine + JSON Analytics Store epoch as long or ISO, convert via ingest pipeline or Kibana "timestamp": {"type": "date", "format": "epoch_millis"}
Amazon Timestream Time-Series Purpose-built for time data, SQL-like query syntax from_milliseconds(epoch) in query or via ingestion mapping
Apache Druid Real-Time Analytics Columnar format, designed for streaming ingestion Ingest epoch as long, define timestampSpec in schema
InfluxDB Time-Series Limited SQL, purpose-built for time-based data Native nanosecond timestamps, converted via Flux or InfluxQL
Loki (Grafana) Log Aggregation No full indexing — optimized for time labels Query via LogQL using | line_format "{{ .Time }}"; epoch handled automatically
SQLite Embedded Relational Not suitable for high-volume logging datetime(epoch, 'unixepoch') or strftime('%s', datetime)
Redis In-Memory Key-Value Volatile, no built-in date handling Store epoch as interger; convert externally (e.g., with Node.js)