|

Day 30 of 100: Dates and Times — Timestamps, Durations, Comparisons

Day 30 of 100 — 100 Days of Playwright with TypeScript Challenge. Phase: JavaScript Fundamentals. JavaScript (Days 1-33) → TypeScript (Days 34-63) → Playwright (Days 64-96) → AI Framework Capstone (Days 97-100).

🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.


Test data needs timestamps. Reports need durations. Assertions compare dates. The Date API handles all three.

Contents

Creating and Reading

const now = new Date();
Date.now();                       // epoch ms — great for unique IDs
now.toISOString();                // '2026-09-30T04:30:00.000Z' — API standard

const due = new Date('2026-12-31');
due.getFullYear();                // 2026
due.getMonth();                   // 11 — ZERO-INDEXED! Dec = 11

🚀 Level Up Your Playwright

From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.

QA Patterns

// Unique test data names
const runId = `run-${Date.now()}`;

// Duration measurement
const t0 = Date.now();
// ... await actions ...
const elapsed = Date.now() - t0;
console.log(`took ${elapsed}ms`);

// Relative dates for test data
const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000);
const lastWeek = new Date(Date.now() - 7 * 86400000);

// Comparing API dates
const created = new Date('2026-09-30T10:00:00Z');
const updated = new Date('2026-09-30T11:00:00Z');
updated > created;               // true — direct comparison works

Gotchas

  • getMonth() is 0-indexed — December is 11
  • Date parsing without timezone assumes local — use ISO strings with Z
  • Never compare formatted strings — compare Date objects or epoch numbers

Tomorrow (Day 31): Sets and Maps — deduplication and lookups.

🎓 Master Playwright End to End

Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.