molecalculator

Moles & Molar Mass

Epoch Calculator: Convert Dates to Unix Time

Calculator No. 01-2437 · Updated · Formula and assumptions shown below

The calculator on this page is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

For study and lab planning. The result follows from the numbers you enter and the formula shown. Check it against your method before you weigh, mix or dilute anything, follow the safety data sheet and your supervisor, and do not use it for clinical, dosing or medication work.

An epoch calculator converts a date and time to the number of seconds—or another chosen unit—since a defined starting instant. For Unix time, that starting point is 1970-01-01 00:00:00 UTC; enter a date, time, and time zone to obtain the corresponding timestamp, or convert a timestamp back to a date.

Formula

Unix time is the elapsed number of seconds from 1970-01-01 00:00:00 UTC. The exact calculation counts the days in each complete year and month before the given date, then adds the elapsed hours, minutes, and seconds in the current day:

timestamp = 86,400 × (days before date) + 3,600h + 60min + s

Here, days before date is the total number of calendar days from 1970-01-01 to the entered date; h is the hour from 0 to 23, min is the minute from 0 to 59, and s is the second from 0 to 59. The output unit is seconds. The calendar uses Gregorian leap-year rules: a year divisible by four is a leap year, except century years unless they are divisible by 400.

The compact expression in the calculator block uses average month and year lengths, so it is not suitable for exact calendar conversion. Exact Unix timestamps require counting actual calendar days. For precision, treat the displayed block as a simplified estimate and use the calendar method below for authoritative values. A proper date calculator must reject impossible combinations such as February 30; the separate month and day inputs shown here cannot validate that relationship.

Worked Example

Using the block’s default inputs—2024-01-01 00:00:00 UTC—the exact calendar calculation is:

  • Days from 1970-01-01 to 2024-01-01: 19,723 days.
  • Seconds per day: 24 × 60 × 60 = 86,400.
  • Timestamp: 19,723 × 86,400 = 1,704,067,200 seconds.

The exact Unix timestamp is 1,704,067,200. The displayed calculator expression is only an approximate formula and does not reproduce this exact result; use an exact Gregorian-calendar implementation for a working conversion.

What “Epoch” Means

An epoch is a reference point from which a system measures elapsed time. It is not one universal date. Unix time, commonly used in programming and data systems, uses midnight at the start of January 1, 1970 in Coordinated Universal Time (UTC). Other systems have different epochs, so a number described only as an “epoch timestamp” may need context before it can be interpreted.

Unix timestamps are usually expressed in seconds, but milliseconds and microseconds are common in software interfaces and data files. A timestamp of 1,704,067,200 seconds corresponds to 1,704,067,200,000 milliseconds. The digits alone do not identify the unit; check the source’s documentation rather than assuming.

How to Convert a Date Correctly

To calculate an exact timestamp, first identify the time zone and convert the local date and time to UTC. Then count whole calendar days from the Unix epoch, including leap days, and add the time of day in seconds. A reliable date-time library is preferable to hand calculation because it handles calendar rules and offsets consistently.

  1. Write the date and time in an unambiguous format, such as 2024-01-01 00:00:00.
  2. Specify the time zone or UTC offset. Do not leave it implicit.
  3. Convert that instant to UTC.
  4. Count elapsed seconds from 1970-01-01 00:00:00 UTC, or use a date-time tool that applies the Gregorian calendar.
  5. Confirm whether the result is in seconds, milliseconds, or another unit.

For dates before 1970, Unix timestamps are negative. For example, 1969-12-31 23:59:59 UTC is −1 second. A negative value is not an error: it records an instant before the epoch.

Time Zones, Leap Seconds, and Calendar Limits

The epoch is defined in UTC, not in the computer’s local time. If a local time is UTC−5, the same clock reading occurs five hours later in UTC; its timestamp is therefore 18,000 seconds greater than if the clock reading were incorrectly treated as UTC. Daylight-saving changes can make local times ambiguous or nonexistent, so include the zone or offset when converting.

Ordinary Unix timestamps generally count seconds while ignoring leap seconds. UTC occasionally inserts a leap second to keep civil time aligned with Earth’s rotation, but most Unix-time conventions do not represent that second as a distinct, consistently handled timestamp. This difference matters in high-precision timing, but not usually in everyday date display or application logs.

Calendar validity is another important constraint. A date such as 2023-02-29 does not exist, while 2024-02-29 does. Any exact calculator must validate the day against the selected month and year. Date-time software may also impose its own supported range, especially for very early or distant future dates.

Common Timestamp Mistakes

  • Mixing units: A 13-digit value is often milliseconds, not seconds, but digit count is only a clue. Verify the format.
  • Ignoring the time zone: The same wall-clock reading represents different instants in different zones.
  • Misreading the epoch: Unix time starts at 1970-01-01 UTC, while other timestamp systems may not.
  • Assuming every day is 86,400 civil seconds: Unix arithmetic uses that count, but local clock days can be shorter or longer when daylight-saving time changes.
  • Dropping fractions: Some systems preserve milliseconds or finer fractions; rounding or truncating them changes the represented instant.

Frequently Asked Questions

What is the Unix epoch date?
The Unix epoch is 1970-01-01 00:00:00 UTC. Unix timestamps measure time relative to that instant, usually in seconds.

How do I convert an epoch timestamp to a date?
Confirm whether the number is in seconds or milliseconds, then interpret it from the Unix epoch in UTC. Convert to a local time zone afterward if needed.

Can an epoch timestamp be negative?
Yes. Negative Unix timestamps represent dates and times before 1970-01-01 00:00:00 UTC.

Is epoch time the same everywhere?
The Unix reference instant is the same, but displaying it as local time produces different clock readings depending on the time zone. Other timestamp standards may use different epochs.

Does Unix time count leap seconds?
Typical Unix timestamps do not provide a distinct, universally consistent count for leap seconds. Systems handle them according to their specific timekeeping conventions.

Related

Formula used
in y | Year | year | 2024 | 1970 | 9999
in mo | Month | month | 1 | 1 | 12
in d | Day of month | day | 1 | 1 | 31
in h | Hour (UTC) | h | 0 | 0 | 23
in mi | Minute | min | 0 | 0 | 59
in s | Second | s | 0 | 0 | 59
out t | Unix timestamp | s | (y - 1970) * 31557600 + (floor((y - 1969) / 4) - floor((y - 1901) / 100) + floor((y - 1601) / 400)) * 86400 + (mo - 1) * 2629746 + (d - 1) * 86400 + h * 3600 + mi * 60 + s | 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 with the constants and conversion factors written on the page, rounded as each result states. See method and constants, the disclaimer or report an error.

More in this section

The whole Moles & Molar Mass section →