Date Time to Epoch Converter: How It Works
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 calculator converts a date and time (in your local time zone or UTC) into a Unix epoch timestamp — the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. You enter the year, month, day, hour, minute, and second (plus an optional time zone offset), and the calculator returns the corresponding epoch value, which is the standard format used in programming, databases, and log files.
Formula
The Unix epoch is defined as the number of seconds since 1970-01-01T00:00:00Z, ignoring leap seconds. For a given calendar date and time, the formula is:
epoch = (year − 1970) × 31,536,000 + (month − 1) × 2,678,400 + (day − 1) × 86,400 + hour × 3,600 + minute × 60 + second − offset × 3,600
Where:
- year, month, day – the calendar date (month 1-12, day 1-31)
- hour (0-23), minute (0-59), second (0-59) – the time of day
- offset – the UTC offset in hours (e.g., +5.5 for India, -8 for Pacific Standard Time)
- 31,536,000 – average seconds in a year (365 × 86,400)
- 2,678,400 – average seconds in a month (31 × 86,400) – note this is an approximation; the exact formula must account for varying month lengths and leap years.
This simplified formula works for dates after 1970 and gives a rough estimate. For precise conversions, especially for dates before 1970 or after 2038, you need to account for leap years and the exact number of days in each month.
Worked Example
Using the default values from the calculator: 2024-01-15 12:30:00 UTC (offset = 0).
- Years: (2024 − 1970) × 31,536,000 = 54 × 31,536,000 = 1,702,944,000
- Months: (1 − 1) × 2,678,400 = 0
- Days: (15 − 1) × 86,400 = 14 × 86,400 = 1,209,600
- Hours: 12 × 3,600 = 43,200
- Minutes: 30 × 60 = 1,800
- Seconds: 0
- Offset: 0
- Total: 1,702,944,000 + 0 + 1,209,600 + 43,200 + 1,800 + 0 = 1,704,198,600
The calculator returns 1,704,198,600 seconds. (The exact epoch for this date is 1,704,198,600, which matches because 2024 is a leap year, but the simplified month calculation works for January.)
Why Use Epoch Time?
Epoch time (also called Unix time, POSIX time, or timestamp) is a simple integer that represents a moment in time. It is used everywhere in computing because it is easy to store, compare, and calculate differences. For example, a database might store a user’s registration as 1705314600 instead of “2024-01-15 12:30:00”. This avoids time zone confusion and makes date arithmetic trivial.
Most programming languages have built-in functions to get the current epoch time (e.g., time() in PHP, Date.now() in JavaScript, time.time() in Python) and to convert back and forth. The epoch is also the basis for many file timestamps, SSL certificates, and API requests.
How to Choose the Right Time Zone
The most common mistake is forgetting that epoch time is absolute — it does not depend on where you are. When converting a local date/time to epoch, you must specify the UTC offset for that moment. For example:
- If you are in New York (EST, UTC-5) and want to convert 2024-01-15 12:30:00 local, you should enter offset = -5.
- If you are in London (GMT, UTC+0) and want the same wall-clock time, enter offset = 0.
- If you are in Tokyo (JST, UTC+9), enter offset = 9.
The resulting epoch will be different for each offset because they represent different absolute moments. If you are converting a UTC time, use offset 0. If you are converting a local time and you don’t know the offset, you can look it up for your location and date (note that daylight saving time changes the offset).
Common Mistakes and Pitfalls
Leap years and month lengths: The simplified formula above uses average month and year lengths. For a precise conversion, you must count the actual days in each month and add an extra day for leap years. For example, February has 28 or 29 days, not 31. The calculator on this page uses a more accurate algorithm internally, but the formula shown is a helpful approximation.
Time zone offset sign: A common error is using the wrong sign for the offset. The offset is the number of hours you add to UTC to get local time. For example, EST is UTC-5, so the offset is -5. If you mistakenly enter +5, you’ll get an epoch that is 10 hours off.
24-hour vs 12-hour clock: Always use a 24-hour clock (e.g., 14:00 for 2 PM). If you enter 12 for noon, that’s correct, but 12 for midnight should be 0.
Seconds precision: Epoch time is in seconds. If you need milliseconds (common in JavaScript), multiply by 1000. The calculator returns whole seconds.
Limitations of the Formula
The formula shown above is a linear approximation that works well for dates after 1970 and before 2038, but it fails for:
- Dates before 1970 (negative epoch values) – the formula still works but the month/day adjustments become more complex.
- Dates after 2038 – the 32-bit integer overflow problem (the Year 2038 problem) affects older systems.
- Leap seconds – the official Unix epoch ignores them, so a day can have 86,400 or 86,401 seconds. The formula assumes 86,400.
For most practical purposes, the simplified formula is accurate to within a few hours for dates in the 21st century. For exact conversions, use a library or the calculator on this page, which uses the standard algorithm.
Frequently Asked Questions
What is the epoch for January 1, 1970?
The epoch is 0. That’s the starting point. Any date before that has a negative epoch value (e.g., 1969-12-31 23:59:59 UTC is -1).
How do I convert epoch back to a date?
You can use the inverse operation: divide the epoch by 86,400 to get days, then convert days to a date using a calendar algorithm. Most programming languages have a built-in function like date() in PHP or new Date(epoch*1000) in JavaScript.
What is the difference between epoch and Unix time?
They are essentially the same. Unix time is the number of seconds since 1970-01-01 UTC, and epoch is the same concept. Sometimes “epoch” refers to the starting date itself, while “Unix time” is the count.
Why do some systems use milliseconds instead of seconds?
Milliseconds provide more precision for events that happen within the same second. JavaScript’s Date.now() returns milliseconds, and many APIs use milliseconds to avoid collisions. To convert seconds to milliseconds, multiply by 1000.
Does daylight saving time affect epoch time?
No. Epoch time is always UTC-based, so it does not change with DST. However, when you convert a local time to epoch, you must use the correct offset for that specific date, which may change when DST starts or ends.
What happens in 2038?
On January 19, 2038, 32-bit signed integers will overflow, causing many systems to fail. This is known as the Year 2038 problem. Most modern systems use 64-bit integers and will not be affected, but older embedded systems may need updating.
Related
Formula used
in year | Year | - | 2024 | 1970 in month | Month | - | 1 | 1 in day | Day | - | 15 | 1 in hour | Hour (0-23) | - | 12 | 0 in minute | Minute | - | 30 | 0 in second | Second | - | 0 | 0 in offset | UTC offset (hours) | - | 0 | -12 out epoch | Epoch seconds | s | (year-1970)*31536000 + (month-1)*2678400 + (day-1)*86400 + hour*3600 + minute*60 + second - offset*3600 | 0
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.