1001Ferramentas
πŸ•’Generators

Random Time Generator

Generate random times (HH:MM:SS) within a window.


  

Random time-of-day generator explained

A random time-of-day generator picks a clock time uniformly within a configurable window (defaulting to 08:00–18:00). It is useful for fixture data (appointment_time, scheduled_at, opening_hours), seeding calendar mock-ups, fuzzing parsers, and generating realistic event logs. Unlike a Unix timestamp, this generator emits only the time component β€” no date attached.

12-hour vs 24-hour clock

The world is split between two notations:

  • 24-hour (ISO 8601, military, most of Europe, Brazil, Portugal): 00:00 to 23:59. Unambiguous, sortable as a string, the only sane choice for storage.
  • 12-hour (US, UK, Australia colloquial): 1:00 AM through 12:59 PM, repeating. Beware the midnight/noon trap: 12:00 AM is midnight and 12:00 PM is noon β€” counterintuitive enough that style guides recommend "12 noon" / "12 midnight".
  • Military time: identical to 24-hour but written without a colon β€” 1430 instead of 14:30, pronounced "fourteen hundred hours".

ISO 8601 time representations

The ISO 8601 standard allows several variants for clock time:

HH:MM             β†’ 14:30           (minute precision)
HH:MM:SS          β†’ 14:30:45        (second precision)
HH:MM:SS.sss      β†’ 14:30:45.123    (millisecond)
HH:MM:SSΒ±HH:MM    β†’ 14:30:45-03:00  (with UTC offset)
HH:MM:SSZ         β†’ 14:30:45Z       (UTC, the "Zulu" suffix)

Some legacy SQL stacks accept HHMMSS without separators; avoid it for new work β€” it confuses humans and date pickers alike.

Time zones and odd offsets

There are 24 nominal time zones, but the real list has many fractional offsets. India uses +05:30, Newfoundland uses -03:30 and Nepal sits on +05:45. A bare time string like 14:30 is ambiguous without a date and a zone β€” that is why ISO 8601 recommends carrying an offset when the value crosses systems.

Daylight Saving Time introduces a deeper ambiguity: on the day the clock falls back, the local time between 01:00 and 02:00 occurs twice. Brazil abolished DST in 2019 (Decreto 9.772/2019), so for new Brazilian data the ambiguity is gone β€” but historical timestamps before 2019 still need careful handling.

Uniform sampling and edge cases

The algorithm is straightforward: convert the lower and upper bounds to seconds-since-midnight, draw a uniform random integer in that range and convert back:

lo = h1*3600 + m1*60
hi = h2*3600 + m2*60
sec = randInt(lo, hi)
out = `${(sec/3600|0).pad(2)}:${((sec/60|0)%60).pad(2)}:${(sec%60).pad(2)}`

One subtle pitfall: an "overnight" range such as 22:00 β†’ 04:00 wraps past midnight, and naΓ―ve subtraction yields a negative window. Handle it by adding 24h to the upper bound and taking the result modulo 24h.

FAQ

Can I restrict to business hours only? Yes β€” set De and AtΓ© to your business window (defaults already cover 08:00–18:00).

Does the output include a time zone? No β€” the generator emits bare HH:MM values. If you need a zone, append it in your own pipeline (e.g. 14:30 America/Sao_Paulo).

Can I get times overnight (22:00 to 04:00)? Most random-time tools assume a same-day window. For overnight, generate two batches (22:00–23:59 and 00:00–04:00) and concatenate.

What is this useful for? Seeding mock created_at, scheduled_at and appointment_time fields, generating random shift schedules for testing scheduling algorithms, simulating arrival times for queueing simulations, and stress-testing time-parsing libraries with realistic input.

Related Tools