Course contentsShow
← JavaScript
Lesson 1613 of 2,72335. Standard Library and Built-insFree lesson

Full Constructor with Hours, Minutes, Seconds

Create precise timestamps using new Date(year, month, day, hours, minutes, seconds, ms) in local time.

Full Constructor with Hours, Minutes, Seconds

You'll learn how to create Date objects with precise timestamps down to the millisecond using all available constructor parameters.

The Complete Date Constructor

So far you've built dates using year, month, and day. JavaScript's Date constructor actually accepts up to seven arguments, allowing you to specify time components in your local timezone:

new Date(year, month, day, hours, minutes, seconds, milliseconds)

All time parameters are optional. If omitted, they default to 0 (midnight values).

Creating Precise Timestamps

Here's how to create a date at exactly 3:45:30 PM on March 15, 2024:

const preciseDate = new Date(2024, 2, 15, 15, 45, 30);
console.log(preciseDate); 
// Fri Mar 15 2024 15:45:30 GMT-...

Add milliseconds for even finer precision:

const veryPrecise = new Date(2024, 2, 15, 15, 45, 30, 500);
console.log(veryPrecise);
// Fri Mar 15 2024 15:45:30.500 GMT-...

Think of It Like Setting a Digital Clock

Imagine you're programming a microwave timer. You don't just set the day it should run—you specify the exact hour, minute, and second. The Date constructor works the same way: each parameter drills down to a finer unit of time.

Practical Example

// Schedule an event for 9:00:00 AM
const meetingStart = new Date(2024, 11, 25, 9, 0, 0);

// Event ends 90 minutes later (we'll manually calculate)
const meetingEnd = new Date(2024, 11, 25, 10, 30, 0);

console.log(meetingStart); // Dec 25 2024 09:00:00
console.log(meetingEnd);   // Dec 25 2024 10:30:00

Key Takeaway: Use new Date(year, month, day, hours, minutes, seconds, ms) to create timestamps with precise time-of-day in your local timezone—perfect for scheduling, logging, or any scenario requiring exact timing.