Set Date Time Unix Epoch Format
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This page explains how to convert a date and time into Unix epoch format (the number of seconds since January 1, 1970, 00:00:00 UTC) and how to do the reverse. You enter a date and time, choose a time zone, and the calculator returns the epoch seconds; you can also enter an epoch number to get the corresponding date and time.
Formula
The core formula for converting a civil date/time to Unix epoch seconds is:
epoch = (serial_date – 25569) * 86400 – tz_offset_hours * 3600
- serial_date – the date/time expressed as a serial number (days since 1900-01-00, as used by spreadsheet software). For 2024-01-15 12:30:00, the serial is 45306.520833.
- 25569 – the serial number for 1970-01-01 00:00:00 UTC.
- 86400 – seconds per day.
- tz_offset_hours – your time zone’s offset from UTC (e.g., +2 for Central European Summer Time, -5 for US Eastern Standard Time).
For the reverse conversion (epoch to date/time):
serial_date = epoch / 86400 + 25569 + tz_offset_hours / 24
Then convert the serial date to a calendar date and time using the standard spreadsheet serial-date algorithm.
Worked Example
Using the default input: date = 2024-01-15 12:30:00, time zone offset = 0 (UTC).
- Convert the date to a serial number. 2024-01-15 is 45,306 days after 1900-01-00 (the spreadsheet epoch). The time 12:30 is 0.520833 of a day. So serial = 45306.520833.
- Subtract 25569 (the serial for 1970-01-01): 45306.520833 – 25569 = 19737.520833.
- Multiply by 86400: 19737.520833 × 86400 = 1,705,321,800. This is the epoch seconds for 2024-01-15 12:30:00 UTC.
The calculator’s formula gives the same result: (45306.520833 – 25569) × 86400 – 0 × 3600 = 1,705,321,800. The reverse output shows the epoch input 1705321800 converts back to 2024-01-15 12:30:00 UTC.
Why the Unix Epoch Exists
The Unix epoch was defined in the early 1970s by the creators of the Unix operating system as a simple, compact way to store timestamps. Instead of storing a date as separate year, month, day, hour, minute, and second fields, they used a single integer counting seconds from a fixed reference point. The chosen reference is 1970-01-01 00:00:00 UTC, which is close to when Unix was first developed. This design makes date arithmetic trivial: adding 86400 to an epoch value moves exactly one day forward, and comparing two timestamps is just an integer comparison.
Over time, the epoch became the de facto standard for time representation in programming languages (C, Java, Python, JavaScript), file systems, network protocols, and databases. Most modern systems store times internally as 32-bit or 64-bit integers of seconds (or milliseconds) since the epoch, converting to human-readable formats only for display.
How to Convert Manually
If you need to convert a date/time to epoch without a calculator, you can follow these steps:
- Determine the number of days between your date and 1970-01-01. Use a day-of-year table or a known reference date. For example, 2024-01-15 is 14 days after Jan 1, 2024, and 2024 is 54 years after 1970. Accounting for leap years (1972, 1976, …, 2020 – that’s 13 leap years), the total days = 54 × 365 + 13 + 14 = 19,737.
- Convert your time to a fraction of a day. 12:30:00 = 12.5 hours = 12.5/24 = 0.520833 days.
- Add the days and fraction: 19,737.520833.
- Multiply by 86400 to get seconds: 1,705,321,800.
- Adjust for your time zone offset: subtract (offset hours × 3600) if you are ahead of UTC, add if behind. For example, if you are in UTC+2, subtract 7200 seconds.
For the reverse, divide the epoch by 86400 to get days, add the offset fraction, then convert the serial date back to a calendar date using a standard algorithm (e.g., the one used by spreadsheet software).
Common Problems and Pitfalls
- Time zone confusion: The epoch is always UTC. If you input a local time without specifying the offset, you will get the wrong epoch. Always convert to UTC first.
- Leap seconds: The Unix epoch ignores leap seconds. It treats every day as exactly 86400 seconds. This means that when a leap second occurs, the epoch value does not advance, and the actual UTC time drifts by one second. Most systems handle this by repeating the same epoch value for two consecutive seconds.
- 32-bit overflow: The classic 32-bit signed integer can hold epoch values up to 2,147,483,647, which corresponds to 2038-01-19 03:14:07 UTC. Systems still using 32-bit time will overflow on that date, causing errors. Modern systems use 64-bit integers, which are safe for billions of years.
- Milliseconds vs seconds: Many APIs and databases store time in milliseconds (e.g., JavaScript’s
Date.now(), Java’sSystem.currentTimeMillis()). Be careful to divide by 1000 when converting to seconds. - Leap year handling: When manually counting days, remember that leap years occur every 4 years, except for century years not divisible by 400. For example, 2000 was a leap year, but 1900 was not.
How to Choose the Right Time Zone
When converting a date/time to epoch, you must know the time zone of the input. If the time is already in UTC, use offset 0. If it is in a local time zone, find the offset from UTC for that specific date, because many regions use daylight saving time. For example, New York is UTC-5 in winter and UTC-4 in summer. The offset changes, so using a fixed offset can be wrong for half the year.
If you are converting an epoch to a date/time, the result depends on the target time zone. The same epoch value represents a different local time in each zone. For most programming tasks, you should convert to UTC first, then apply the local offset for display.
For the calculator, the time zone offset is expressed in hours, which can be fractional (e.g., 5.5 for India, 9.5 for Australia Central). The formula handles fractional offsets correctly because it multiplies by 3600 seconds per hour.
Alternatives to Unix Epoch
While the Unix epoch is ubiquitous, other time representations exist:
- ISO 8601 strings: Human-readable text like “2024-01-15T12:30:00Z�. This is easier to read but takes more space and is slower to parse.
- Julian Day Number: A continuous count of days since noon on January 1, 4713 BC. Used in astronomy. The Unix epoch is approximately Julian Day 2440587.5.
- File time (Windows): 100-nanosecond intervals since January 1, 1601. Used by Windows file systems.
- NTP timestamps: 64-bit timestamps used in network time protocol, counting seconds since 1900-01-01.
- Excel serial dates: Days since 1900-01-00 (or 1904-01-01 on Mac). The formula in this calculator uses this internally.
Each has its own reference point and granularity, but the Unix epoch remains the most common for general-purpose programming because of its simplicity and wide support.
Frequently Asked Questions
What is the Unix epoch exactly?
The Unix epoch is the reference point from which Unix time is measured: January 1, 1970, 00:00:00 UTC. Unix time is the number of seconds that have elapsed since that moment, excluding leap seconds. It is stored as an integer, typically 32-bit or 64-bit, and is used by most operating systems and programming languages.
Why is 1970 the start date?
1970 was chosen by the early Unix developers because it was close to the time they were working, and it allowed them to use a simple 32-bit integer to represent dates for the foreseeable future. The exact reasoning is not documented, but it was a convenient, round date that was already in use in some systems.
How do I get the current Unix epoch in my terminal?
On Linux, macOS, or Windows with a Unix-like shell, type date +%s. In Python, use import time; print(int(time.time())). In JavaScript, use Math.floor(Date.now() / 1000). These all return the current epoch seconds.
What happens on January 19, 2038?
If a system uses a 32-bit signed integer for Unix time, it will overflow at 03:14:07 UTC on that date, wrapping to a negative number. This is known as the Year 2038 problem. Most modern systems use 64-bit integers, which will not overflow for billions of years, but legacy systems may need updates before that date.
Is Unix time the same as UTC?
No. Unix time is a count of seconds since the epoch; UTC is a time standard with hours, minutes, and seconds. Unix time is defined in terms of UTC, but it does not include leap seconds. When a leap second occurs, Unix time simply repeats the same second, so the two can diverge by up to a second.
Can I convert a date before 1970 to epoch?
Yes, but the epoch value will be negative. For example, 1969-12-31 23:59:59 UTC is epoch -1. The calculator and the formula handle negative numbers correctly, as long as your system supports signed integers.
Related
Formula used
in dt | Date and time (YYYY-MM-DD HH:MM:SS) | - | 2024-01-15 12:30:00 | 0 in tz | Time zone offset from UTC (hours) | h | 0 | -12 in ep | Epoch seconds (for reverse) | s | 1705321800 | 0 out epoch | Epoch seconds | s | (dt - 25569) * 86400 - tz * 3600 | 0 out back | Date and time from epoch | - | ep / 86400 + 25569 + tz / 24 | 6
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.