Lesson 74
30 XP

Digital Clock

Create a Real-Time Clock Display

Step 1 of 5

Understanding Time in JavaScript

JavaScript has a built-in Date object that represents a single moment in time. We can use it to get the current time and update it every second.

Date Object Methods:

  • getHours(): Returns hour (0-23)
  • getMinutes(): Returns minutes (0-59)
  • getSeconds(): Returns seconds (0-59)
  • getDay(): Returns day of week (0-6)
// Get Current Time
const now = new Date()
const hours = now.getHours()
const minutes = now.getMinutes()
const seconds = now.getSeconds()

Live Clock:

02:13:16
Wednesday