Time · 7 min read

How to Use Timestamp Explorer: Real-World UI States From Milliseconds

A stored instant is raw material. Here is how to derive the states a UI actually needs — created, expires, is expiring soon — with comparisons you can trust.

Why a stored instant is never enough

Every product surface that deals with time starts from the same raw material: one or two integers. A feature row carries released_at; a trial account carries created_at and an expires_at. Those numbers are complete as instants and mute as interface. No user has ever read a badge that says 1700000000. Between the stored instant and what the screen shows sits a layer of derived state: a New badge during the first two days, an amber Expiring soon warning with a live countdown, a read-only mode during a grace period, a gray Expired label once it closes. None of those states exist in the database. Every one of them is computed at render time, from comparisons between the current moment and the stored timestamps.

That comparison layer is where time bugs live, and they are rarely exotic. A trial that shows as expired on day one. A countdown that reads "2 days left" for three days. A New badge that never goes away for users in one region. Each symptom traces back to the same root: comparisons were written against numbers nobody had pinned down first — which unit, which timezone, which exact boundary. Distributed teams feel this hardest, because the same instant legitimately renders as two different calendar dates on two continents, and any logic that treats a date label as if it were the instant itself will disagree with itself.

The fix is unglamorous and reliable: before writing any UI time logic, derive the exact instants the interface will compare against. That is a job for a tool, not for mental arithmetic at the end of a long day.

The workflow: pin down the exact instants first

Suppose a feature ships at epoch second 1700000000 and a trial attached to it expires seven days later. Four questions need exact answers before a single comparison is coded: When does it go live? When does the trial end? When does the Expiring soon state begin? When does the grace period end? Open the Timestamp Explorer and work through them in order.

Step 1 — confirm the unit. Paste the stored value and read it both ways. The value is ten digits, which fits seconds at today's epoch; the explorer confirms that reading it as milliseconds instead lands in April 1970, so seconds it is. If this step feels optional, see our guide on timestamp unit confusion — it documents the wreckage that skipping it leaves behind.

Step 2 — compute the derived instants. Seven days is 604,800 seconds. Add that to the release instant, then read every result back as a human date to sanity-check it:

Input:             1700000000             (10 digits -> seconds)
As UTC:            2023-11-14T22:13:20Z   release instant

7 days             7 × 86400   =  604800 seconds
Expiry (seconds):  1700000000 + 604800  =  1700604800
As UTC:            2023-11-21T22:13:20Z   trial ends

Expiring soon:     1700604800 - 86400    =  1700518400   (24 h before expiry)
Grace ends:        1700604800 + 259200   =  1700864000   (3 days after)

Each derived value goes back through the explorer immediately. Mental arithmetic that adds a time period is exactly where off-by-one-day errors are born; reading the result back as a date catches them while they are still free to fix.

Step 3 — check the rendering in other timezones. The expiry is one instant, but it wears different local clothing depending on the viewer. The explorer renders the same moment in several zones side by side:

1700604800000  (the expiry, in milliseconds)

UTC:        Tue 2023-11-21 22:13:20
Tokyo:      Wed 2023-11-22 07:13:20   (+09:00)
New York:   Tue 2023-11-21 17:13:20   (-05:00, standard time)

Tokyo users see the trial expire on November 22; New York users see November 21. Both are correct, and neither is the "real" date — the real thing is the instant. Any UI that renders a date-only label ("Expires Nov 21") must accept that the label changes with the viewer's zone, and any server that bakes the label into an email or a stored string has frozen one viewer's presentation into everyone's data. Making this derivation a habit, not a one-off, is what our guide on a repeatable timestamp decoding process is about.

The state machine: before, active, grace, expired

With the instants pinned, the UI's time behavior becomes a small state machine: intervals on a number line, separated by exact boundaries. Writing the boundaries in milliseconds — one consistent unit everywhere — turns vague requirements into checkable comparisons:

UI stateComparison (now in ms)What the user sees
Beforenow < 1700000000000Feature hidden or locked; "Coming soon" label
Newnow < 1700172800000"New" badge, first 48 hours after release
Expiring soonnow ≥ 1700518400000 and now < 1700604800000Amber badge plus live countdown to the deadline
Activenow < 1700604800000Normal interface, no time decoration
Gracenow ≥ 1700604800000 and now < 1700864000000Read-only mode; "Expired — renew within 3 days"
Expirednow ≥ 1700864000000Gray "Expired" label; data archived or locked

The same boundaries as code. Every comparison is a millisecond comparison; every threshold comes from the derivation step above, not from a number remembered at the keyboard:

function ui_state(now_ms, feature):
    if now_ms < feature.released_at_ms:              # 1700000000000
        return BEFORE
    if now_ms >= feature.expires_at_ms:              # 1700604800000
        if now_ms < feature.expires_at_ms + 259200000:
            return GRACE                             # read-only, renewing allowed
        return EXPIRED
    if now_ms >= feature.expires_at_ms - 86400000:
        return EXPIRING_SOON                         # amber badge + countdown
    if now_ms < feature.released_at_ms + 172800000:
        return NEW                                   # first 48 hours
    return ACTIVE

Two conventions keep this function honest. First, decide once whether boundaries belong to the earlier or later state — here each boundary opens the later state — and apply that rule everywhere, because a boundary claimed by two states is a flicker waiting to happen. Second, never store the derived state. It is recomputed from the instants on every render, so a deployed fix or a changed grace period updates the UI without a data migration.

Three pitfalls that survive code review

The thousandfold bug: seconds meeting milliseconds

The most common failure in comparison code is a unit mismatch at the comparison itself. The server sends seconds; the client compares against Date.now(), which is milliseconds:

const now = Date.now();            // milliseconds: about 1.7 × 10^12
const expiresAt = 1700604800;      // seconds, straight from the API

if (now > expiresAt) {
  showExpiredBanner();             // fires on day one — every trial "expired"
}

Any millisecond value dwarfs any second value, so a seconds deadline compared against a millisecond clock reads as permanently in the past: every trial expires instantly, every release is already live, nothing is ever "new." Run the mismatch the other way — millisecond deadline against a second-based clock — and nothing ever expires until the year 55827. The tell is total: not some rows wrong, but all rows wrong in the same direction. The fix is normalization at the boundary: convert incoming values to milliseconds exactly once, on entry, and let every comparison downstream assume that unit. The digit-count checks in our unit confusion guide catch which way a given value points.

Server UTC versus browser local

The second pitfall is not about the comparison at all — it is about rendering the same moment differently on different machines. A server formats the expiry in its own UTC locale and logs "expires 2023-11-21 22:13"; a browser in Tokyo renders the identical millisecond as "Nov 22, 07:13." Nothing is broken, yet a bug report arrives claiming the trial "expired a day early," and the log line makes the report look false. The resolution is discipline: comparisons happen against raw instants in one unit, rendering happens at the very edge of the system, in the viewer's timezone, as late as possible. A date-only badge ("Expires Nov 21") is presentation and must be computed from the instant at render time — never cached from another zone's rendering.

Daylight saving inside a countdown

The third pitfall hides in the arithmetic of "seven days later." There are two ways to add seven days, and they disagree whenever a clock change falls inside the window:

Start (New York):  Sat 2025-11-01 15:00 EDT  =  2025-11-01T19:00:00Z

Add 168 hours:                                    2025-11-08T19:00:00Z
  rendered locally:   Sat 2025-11-08 14:00 EST    (the week had 167 hours)

Add 7 wall-clock days (keep 15:00):               2025-11-08T20:00:00Z
  rendered locally:   Sat 2025-11-08 15:00 EST    (one hour later)

Both results are defensible — which one is correct depends on what the product promised. A countdown computing remaining milliseconds from a stored expiry is immune to the shift, because elapsed time is elapsed time. But code that derives an expiry from a calendar operation ("created November 1, plus seven days") picks one branch or the other, and the choice silently moves the deadline by an hour. The rule: compute deadlines by adding exact durations to stored instants, and only use calendar arithmetic — through a real timezone library — when the requirement genuinely says "same local time."

One unit, one comparison: convert every stored timestamp to integer milliseconds at the boundary, compare only in milliseconds, and render only at the display edge. Nearly every UI time bug is one of those three rules being broken somewhere.

Test data generation: fixed instants instead of relative guesses

The states are only as trustworthy as the tests that exercise them, and time-based tests fail in a characteristic way: they use "now plus a bit" arithmetic that drifts, races, or crosses a boundary it did not mean to cross. The reliable pattern has two stages.

First, use the explorer's Use current time feature to capture a real "now" as a baseline — useful for smoke checks that answer "do the intervals look sane today?" Second, craft fixed instants for the automated suite: hard-coded boundary values, each paired with cases one millisecond on either side. Fixed values make tests deterministic, and the one-millisecond neighbors pin the boundary convention itself:

RELEASE_MS    = 1700000000000   # 2023-11-14T22:13:20Z — goes live
NEW_END_MS    = 1700172800000   # +48 h   — "New" badge stops showing
WARN_MS       = 1700518400000   # expiry - 24 h — "Expiring soon" begins
EXPIRY_MS     = 1700604800000   # 2023-11-21T22:13:20Z — trial ends
GRACE_END_MS  = 1700864000000   # +3 days — read-only period closes

# For each boundary B, run three cases:
#   B - 1  must show the earlier state
#   B      must show the later state
#   B + 1  must show the later state
# Two extra fixtures bracket the whole machine:
#   RELEASE_MS - 1     BEFORE
#   GRACE_END_MS + 1   EXPIRED

Because the fixtures are absolute instants, they render identically no matter when or where the suite runs, and a failure points at a specific boundary rather than a vague "somewhere around Thursday." After any fix, a short review against a structured list of what to re-check keeps the machine from regressing — the items in our timestamp audit checklist map directly onto the states above.

Test it yourself

Paste 1700000000 into the Timestamp Explorer and walk the same three steps: confirm the unit, add seven days and read the result back as a date, then switch the rendering timezone and watch the calendar date move under a constant instant. Every threshold in the state table, every test fixture, and every pitfall example in this guide is reproducible in a browser tab in under a minute.

Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.