Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Working with Dates – `Date` objec | JavaScript Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. JavaScript Course

Lesson 17 of 55

·javascript

Working with Dates – `Date` object & Intl

8 mins

Course progress31%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • The **`Date`** constructor parses many ISO‑8601 formats but can be inconsistent across browsers for other formats.
  • Use **`Intl`** for proper localisation of numbers, dates, and currencies.
  • For heavy date manipulation consider a library like **date‑fns** or **Luxon**.

Create a date:

const now = new Date();
const specific = new Date('2024-02-27T10:00:00Z');

Common methods:

  • getFullYear(), getMonth(), getDate() – retrieve parts.
  • toISOString(), toLocaleString() – format output.

Intl.DateTimeFormat for locale‑aware formatting:

const fmt = new Intl.DateTimeFormat('de-DE', { dateStyle:'short', timeStyle:'short' });
console.log(fmt.format(now)); // 27.02.24, 11:00

Example: Countdown timer

const end = new Date('2024-12-31');
setInterval(()=>{
  const diff = end - new Date();
  if(diff<=0){ clearInterval(this); console.log('Happy New Year!'); }
  else{ console.log(Math.floor(diff/1000)+' seconds left'); }
},1000);
Make it stickPractice what you've learned1 quiz · 7 practical tests · Optional activities from JavaScript CourseBrowse activities
Previous lessonError Handling – try/catch, Custom Errors & DebuggingContinue to lesson 18Regular Expressions – `RegExp` & String MethodsBack to JavaScript Course curriculum