Long counters that count in nanoseconds

Operating systems, databases and programming languages often keep elapsed time as an integer number of nanoseconds, because an integer avoids rounding and gives fine resolution. The trouble comes when someone reads a raw value such as 259,200,000,000,000 and has to say how long that is. This page divides by the number of nanoseconds in a day and answers in days, so that value becomes 3 d. It suits developers checking a timeout constant, administrators reading an uptime counter, and students converting between the scales of a computer clock and a calendar. The page works on durations only, so it never needs a date, a time zone or a start point.

Eighty-six billion four hundred million, times a thousand

A day has 24 hours, an hour has 60 minutes and a minute has 60 seconds, so a day is 86,400 s. A second holds one billion nanoseconds, which puts a day at 86,400,000,000,000 ns, or 8.64 × 10^13. The formula on the page is d = ns × 1.15740740741e-14. The SI second is the base, and the minute, hour and day are accepted non-SI units whose definitions NIST SP 811 and the SI Brochure state in seconds. A fixed day here is exactly 86,400 s. The factor is a repeating decimal, so the page keeps it at full precision internally and only the displayed answer is shortened.

Ten nanoseconds against a whole day

With the default 10 ns the page returns 1.15740740741e-13 d. That figure shows how little time ten nanoseconds is when measured against a day: about one part in 8.6 trillion. One hour of elapsed time, which is 3,600,000,000,000 ns, gives 0.0416667 d, and 172,800,000,000,000 ns is exactly 2 d. A job duration reported as 150,000,000,000,000 ns converts to 1.7361 d, or about 41 hours and 40 minutes. Scientific notation is the reliable way to copy tiny answers, so read the e-13 as 10^-13 and keep the exponent whenever the number moves into a spreadsheet or a ticket.

Where a 64-bit nanosecond counter runs out

A signed 64-bit integer holds values up to 9,223,372,036,854,775,807. If each unit is one nanosecond, that is 106,751.99 days. Dividing by 365 gives about 292 years, which is why a language that stores a duration in an int64 of nanoseconds can represent only about 292 years either way from its zero. For ordinary timeouts and uptimes this is far more than enough, but it explains why code that converts a decade into nanoseconds still fits, while a span of several centuries can overflow. Pasting the maximum value into the page confirms the day count, which helps when you write a boundary test or document the limit of an interface.

Reading a retention or timeout setting

Configuration files for caches, queues and logging often store lifetimes in nanoseconds. A value of 604,800,000,000,000 appears in a setting, and the question is how long that really is. Divide by 86,400,000,000,000 and the answer is 7 days. A value of 2,592,000,000,000,000 is 30 days, a common monthly retention period, and 86,400,000,000,000 is a single day. Seeing the unit in days makes mistakes obvious: a retention intended as one week but written with one extra zero would convert to 70 days. The page returns the same ratio whatever the magnitude, so you can paste a suspicious constant and see at once whether its scale matches the policy it is supposed to express.

Fixed 24-hour days and local calendar days

The page treats a day as 86,400 seconds without exception. A local calendar day can be 23 or 25 hours long where clocks change for daylight saving, and a calendar month or year varies in length, so neither can be derived from a nanosecond count alone. If you subtract two timestamps that cross a clock change, the elapsed time is still a whole number of 24-hour days only when the true elapsed seconds say so. Billing, subscriptions and scheduling that follow the local date need a calendar library, with the time zone and the dates, instead of a division. Use this converter for the elapsed duration and a date library for the calendar.

Reporting a short interval in days

Reporting a duration in days only makes sense when the value is large enough for the unit. A task that took 2,500,000,000 ns is 2.5 s, and giving it as 0.0000289 d hides the information readers want. Choose the unit that puts the number between about 1 and 1,000: seconds for the task above, hours or days for a long batch run. The converter is still useful for checking that two systems agree. If a dashboard shows 3.47 d and your own counter shows 299,808,000,000,000 ns, the page confirms they match to the digits you entered. Keep both the raw ns value and the day figure in the record, so a reviewer can follow the conversion.

Precision, rounding and reverse checks

The page keeps the full factor, converts through the base unit and rounds only the final value, which it shows with up to twelve significant digits. A rounded day figure will not necessarily convert back to the original nanosecond count, because the digits you copied are fewer than the digits that were stored. Reverse the units and enter the rounded answer to see the size of the difference. The accuracy of the original measurement matters more than the digits shown: a counter that is read with a few microseconds of jitter does not justify twelve digits in a day figure. State the resolution of your clock next to the result, and avoid comparing converted numbers for exact equality in code.

Spotting a unit mix-up in an exported column

Exports from monitoring tools sometimes label a column as nanoseconds when it holds another unit. A day expressed in nanoseconds is 86,400,000,000,000, and a day expressed in microseconds is 86,400,000,000. If a field that should show a one-day interval holds the smaller number, entering it here as ns returns 0.001 d, which is 86.4 s. That result tells you the column is off by a factor of 1,000, most likely microseconds, and not that the job ran for a minute and a half. Run the page on a known value, such as one day, before you trust a bulk conversion. A single check against a number you can verify by hand prevents a whole table from carrying the same scale error.