~10 min
A new Minecraft world runs on a clock the moment you spawn. A full day/night cycle lasts 20 real-world minutes: about 10 minutes of daylight, roughly 8 minutes and 20 seconds of night, and about 50 seconds each of dusk and dawn in between. Daylight is safe — hostile mobs can't spawn out in the open while the sun is up. That safety starts draining away at dusk, and by full night the danger is everywhere the light doesn't reach.
Ten minutes sounds like plenty of time, and for an experienced player it is. For a first character, it goes fast: chopping a tree for wood, crafting a table and some basic tools, and finding a spot to hole up all eat into that window. The practical rule is simple — start looking for shelter well before the sky begins to darken, not after. Waiting until you can see the sun touching the horizon is waiting too long.
What actually lets a hostile mob like a zombie or skeleton appear isn't just "is it dark outside" — it's a pair of light checks at the exact block where it would spawn. In the Overworld, a hostile mob can only spawn on a block where the block light is 0 (no torches, lava, glowstone or other light source reaching it) and the sky light is 7 or lower, which covers anywhere not standing in open daylight, including caves and the inside of any roofed structure.
That second condition is why a roof over your head isn't enough on its own — a dark, unlit room under a roof still has sky light low enough to pass that check every time. The block light check is the one you actually control. Any light source that reaches a block at all raises its block light above 0, and that alone is enough to stop a hostile mob from spawning there, regardless of how dark the sky is.
Put those two rules together and a first shelter is really just two jobs: seal every gap, then light every block. Sealing means no exposed 1-block gaps in your walls, floor or roof — a single opening is enough for a mob to walk in, or for arrows to reach you from outside. It doesn't need to be pretty; digging three blocks into a hillside and covering the entrance with a placed block does the job as well as a built structure.
Lighting means placing torches, or any light source, often enough that no floor block inside sits at block light 0. A torch's light fades with distance, so spacing several torches across a room is safer than one torch in a corner. Once your space is sealed and lit, you can safely wait out the night, sleep in a bed to skip straight to morning if you have one, or step outside to fight on your own terms.
Yes — an enclosed room isn't automatically safe. Sky light is already low enough inside, so with block light also at 0 in the dark, every hostile-mob spawn condition is met.