Generate Random Time
Pick random times of day between any two times, including overnight windows such as 22:00 to 06:00. Choose steps from any second to whole hours, avoid repeats, and show the results as 12-hour, 24-hour or military times, or as analogue clock faces for reading practice.
Every time on your step inside the window equally likely
Worked Example: A Clock-Reading Worksheet
A Year 2 / Grade 2 teacher wants twelve clocks to read to the nearest five minutes, with the answers on a separate sheet.
Step 1: Load the worksheet preset
Step 2: Print the questions
Step 3: Make the answer key
Match the step to the year group. The US Common Core standards build the skill in three stages, and the step setting maps onto each:
| Grade | Standard | Use step |
|---|---|---|
| 1 | Tell time in hours and half-hours | 30 minutes |
| 2 | To the nearest five minutes, using a.m. and p.m. | 5 minutes |
| 3 | To the nearest minute; intervals in minutes | Whole minutes |
Where the Hands Point at a Random Time
The minute hand moves 6° a minute (360° ÷ 60). The hour hand moves 30° an hour, and keeps creeping between the numbers at 0.5° a minute. The clock faces here draw both hands that way, which is the detail children most often miss.
Example: 3:40
At 3:40 the hour hand is two-thirds of the way from 3 to 4, not on the 3. A child who reads "3" from a short hand near the 4 is reading correctly; one who says "4:40" has fallen for the classic trap. Random times on 5-minute steps give plenty of these near-the-next-hour cases.
Time Windows, Steps and Overnight Shifts
Both ends of the window are included, and a time only counts if it lands on the step, counted from midnight: with 15-minute steps you get :00, :15, :30 and :45, never 9:07. If To is earlier than From, the window runs past midnight, so 22:00 to 06:00 means a night shift, not an error. With In time order, overnight results are sorted from the start of the shift, so 23:10 comes before 01:30.
| Window | Step | Possible times |
|---|---|---|
| 09:00 to 17:00 | 15 minutes | 33 |
| 09:00 to 17:00 | Whole minutes | 481 |
| 22:00 to 06:00 | Whole minutes | 481 |
| 00:00 to 23:59 | Whole minutes | 1,440 |
| 00:00:00 to 23:59:59 | Any second | 86,400 |
Random times are spread evenly through the window. Real events rarely are: website visits, calls and logins bunch around busy hours. Even spacing is ideal for testing that software handles every time correctly, less so for imitating real traffic. To attach dates as well, combine these with the random date generator.
12 a.m., 12 p.m., Noon and Midnight
The hour after midnight and the hour after noon are where 12-hour times trip people up. Strictly, noon is neither "before noon" (a.m.) nor "after noon" (p.m.), which is why NIST recommends writing "12 noon" and "12 midnight". By convention clocks show 12:00 PM for noon and 12:00 AM for midnight, as this page does:
| 24-hour | 12-hour | Plain words |
|---|---|---|
| 00:00 | 12:00 AM | Midnight, the start of the day |
| 00:30 | 12:30 AM | Half past midnight |
| 11:59 | 11:59 AM | One minute before noon |
| 12:00 | 12:00 PM | Noon |
| 12:30 | 12:30 PM | Half past noon |
| 23:59 | 11:59 PM | One minute before midnight |
For more on four-digit times, including 2400 and Zulu time, see the military time converter.
One Time, Written Six Ways
| Representation | 14:30:15 becomes | Used by |
|---|---|---|
| 12-hour | 2:30:15 PM | Everyday US, UK informal |
| 24-hour (ISO 8601) | 14:30:15 | Timetables, most of the world, data files |
| Military | 1430 | Armed forces, aviation, hospitals; seconds dropped |
| Seconds since midnight | 52,215 | Code and databases (3,600 × 14 + 60 × 30 + 15) |
| Minutes since midnight | 870.25 | Scheduling maths |
| Fraction of a day | 0.604340 | What spreadsheets store behind a time cell |
With "Times on" set to Any second, the generated times include seconds; with any other step, seconds are always :00 and are left off.
Random Times in Python and JavaScript
Python: a 15-minute slot between 09:00 and 17:00
import random
from datetime import time
secs = random.randrange(9 * 3600, 17 * 3600 + 1, 900) # end included, 900 s = 15 min
slot = time(secs // 3600, secs % 3600 // 60) # e.g. 13:45JavaScript: any minute of the day as HH:MM
const m = Math.floor(Math.random() * 1440);
const hhmm = `${String(Math.floor(m / 60)).padStart(2, '0')}:${String(m % 60).padStart(2, '0')}`;Work in whole seconds or minutes since midnight, as both snippets do, and convert to text at the end. For an overnight window, add the offset to the start time and take the remainder after dividing by 86,400.
Frequently asked questions
How do I pick a random time between two times?
Enter the earliest time in From and the latest in To. Both are included. Choose a step such as 15 minutes if you only want round times.
Can the window cross midnight?
Yes. If To is earlier than From, the window runs through midnight, so 22:00 to 06:00 gives times from the evening and the early morning only.
How do I make printable clock faces?
Tick Show clock faces, untick Show the times for the question sheet, and print. Tick Show the times again for the answer key; the clocks stay the same until you generate again.
Does it pick a time zone?
No. These are clock times without a date or time zone, like the time on a timetable. Add a date and zone yourself if you need a full timestamp.
Sources
- NIST: Times of Day FAQs: why 12 a.m. and 12 p.m. are ambiguous.
- Common Core State Standards: Grade 1 Measurement & Data: telling time in hours and half-hours.
- Common Core State Standards: Grade 2 Measurement & Data: to the nearest five minutes, with a.m. and p.m.
- Common Core State Standards: Grade 3 Measurement & Data: to the nearest minute and time intervals.
- RFC 3339: Date and Time on the Internet: the 24-hour partial-time format.
- Python documentation: random module: randrange with a step.
Related Tools
Create GUIDs for Microsoft and .NET fields.
Generate binary numbers with a chosen bit length.
Create a random pixel image and save it as a PNG.
Generate bytes in hex, Base64, or decimal format.
Pick a date between your chosen start and end dates.
Generate decimals with a chosen range and precision.