Skip to content

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

From 1:00 to 12:55 · times on 5 minutes · 12 times · no repeats · clock faces on · times hidden

Step 2: Print the questions

Each card shows a clock face and a blank __ : __ line for the answer

Step 3: Make the answer key

Tick Show the times and print again: same clocks, now labelled

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:

Clock-reading expectations by grade and the matching step setting
GradeStandardUse step
1Tell time in hours and half-hours30 minutes
2To the nearest five minutes, using a.m. and p.m.5 minutes
3To the nearest minute; intervals in minutesWhole 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.

minute hand = 6° × minutes · hour hand = 30° × hours + 0.5° × minutes

Example: 3:40

Minute hand 6 × 40 = 240° · hour hand 30 × 3 + 0.5 × 40 = 110° · angle between them 130°

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.

Number of possible times for common windows and steps
WindowStepPossible times
09:00 to 17:0015 minutes33
09:00 to 17:00Whole minutes481
22:00 to 06:00Whole minutes481
00:00 to 23:59Whole minutes1,440
00:00:00 to 23:59:59Any second86,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 times around noon and midnight in 12-hour form
24-hour12-hourPlain words
00:0012:00 AMMidnight, the start of the day
00:3012:30 AMHalf past midnight
11:5911:59 AMOne minute before noon
12:0012:00 PMNoon
12:3012:30 PMHalf past noon
23:5911:59 PMOne minute before midnight

For more on four-digit times, including 2400 and Zulu time, see the military time converter.

One Time, Written Six Ways

The time 14:30:15 in different representations
Representation14:30:15 becomesUsed by
12-hour2:30:15 PMEveryday US, UK informal
24-hour (ISO 8601)14:30:15Timetables, most of the world, data files
Military1430Armed forces, aviation, hospitals; seconds dropped
Seconds since midnight52,215Code and databases (3,600 × 14 + 60 × 30 + 15)
Minutes since midnight870.25Scheduling maths
Fraction of a day0.604340What 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:45

JavaScript: 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