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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

Lesson 17 of 55 · javascript

Working with Dates – `Date` object & Intl

Duration: 8 mins

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);
Previous: Error Handling – try/catch, Custom Errors & DebuggingNext: Regular Expressions – `RegExp` & String Methods