ProgramGuru

Represent Dates and Time Explicitly

Represent Dates and Time Explicitly

A Date represents an instant in time. An ISO timestamp with Z identifies UTC, and UTC methods avoid depending on the machine's local timezone for this school deadline example.

Before this topic, review Produce a Sequence on Demand if its terms are unfamiliar.

What you’ll learn

  • Explain represent dates and time explicitly through the school example.
  • Trace the shown operations and distinguish their result from displayed output.
  • Make the practice change and explain its consequence: The explicit UTC instant now falls in February on the twentieth day.

Work through the school example

This is JavaScript using language features and the host console. Read the initial values, then follow each operation to its displayed result. A declaration names a value, a function call performs an operation, and console.log displays its arguments.

JavaScript · school.js · complete example

const deadline = /* @__PURE__ */ new Date("2026-01-15T09:00:00Z");
console.log(deadline.getUTCMonth() + 1);
console.log(deadline.getUTCDate());

Expected output

1
15
Run in JavaScript compiler →

Recognize the important boundary

Month indexes start at zero. A local calendar date, timezone and instant are different concepts; avoid ambiguous date-string parsing.

Try a small variation

JavaScript · original source for practice

const deadline = /* @__PURE__ */ new Date("2026-01-15T09:00:00Z");
console.log(deadline.getUTCMonth() + 1);
console.log(deadline.getUTCDate());

Your task: Replace 01-15 with 02-20. Predict the result before running the edited program.

The source is repeated here. If the edit targets the HTML rather than the script, use the markup repeated below; the worked answer also repeats the changed markup.

Worked answer and reasoning

The explicit UTC instant now falls in February on the twentieth day.

JavaScript · complete worked variation

const deadline = /* @__PURE__ */ new Date("2026-02-20T09:00:00Z");
console.log(deadline.getUTCMonth() + 1);
console.log(deadline.getUTCDate());

Expected output

2
20
Run in JavaScript compiler →

Predict the original program

JavaScript · original program for this question

const deadline = /* @__PURE__ */ new Date("2026-01-15T09:00:00Z");
console.log(deadline.getUTCMonth() + 1);
console.log(deadline.getUTCDate());
What does the original JavaScript program display, in order?
Choose one answer. You can try again.

Answer and explanation

1 → 15

A Date represents an instant in time. An ISO timestamp with Z identifies UTC, and UTC methods avoid depending on the machine's local timezone for this school deadline example. Month indexes start at zero. A local calendar date, timezone and instant are different concepts; avoid ambiguous date-string parsing.

Keep the useful idea

A Date represents an instant in time. An ISO timestamp with Z identifies UTC, and UTC methods avoid depending on the machine's local timezone for this school deadline example.

Check your variation against this explanation: The explicit UTC instant now falls in February on the twentieth day.

Use the JavaScript array reference library for individual array operations and boundary tests to check a rule independently.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Match a Simple Text Pattern →