Blog/NotesConcept

Understand JavaScript Date Object with Examples (for JavaScript Interviews)

Go through different ways to display dates using javascript date object. It covers examples of date object usage to understand the main concepts of javascript date object.

Intermediate

Anuj Sharma

Last Updated Jun 15, 2026


Understand JavaScript Date Object with Examples (for JavaScript Interviews)

Working with date in javascript has very common use-case in web applications, and date-related operations can be achieved using Javascript Date Object. There are many methods supported by Date Object which makes it very easy to work with date in javascript.

Table of Content

  1. Ways to Create JavaScript Date Object
  2. Commonly used Static & Instance Methods of Date Object
  3. Common use-cases of javascript date object in Frontend Interviews

Ways to Create JavaScript Date Object

JavaScript Date Object

Date object supports 4 types of constructor functions to create a new object 

💡 Number of milliseconds since midnight at the beginning of January 1, 1970, UTC — also known as the epoch

1. No parameter new Date()

This constructor doesn't take any parameter and provides a string representation of date time.

Example

const date = new Date();
// "2025-01-05T11:29:53.357Z"

2. Epoch value parameter - new Date(epoch value)

This constructor takes the integer epoch value (in milliseconds), this input is the same which returned by Date.now() method. It returns the date-time in string format.

Example

// Epoc value - 1736076951966 in millisecond

const date = new Date(1736076951966);
// 2025-01-05T11:35:51.966Z

3. Date string - new Date(date string)

This constructor takes the date string and returns the date object representing the same date string.

Example

const date = new Date("2025-01-07T11:45:51.966Z");

// 2025-01-07T11:45:51.966Z

4. Date time Individual Value - new Date(year, month, <day>, <hour>, <minute>, <second>, <millisecond>)

This parameter can take the individual values of date time parameters. In this date, constructor year and month parameters are mandatory to pass and other parameters are optional.

Example

const date = new Date(2025, 01, 04, 3, 24, 0);

// 2025-02-03T21:54:00.000Z

Commonly Used Static & Instance Methods of Date Object in JavaScript

There are many Static and instance methods supported by date objects, lets check out the most common static and instance methods of Date Objects in javascript. These methods will help to handle any date-related use-case in Machine Coding and javascript interview rounds.  

1. Static Date.now()

static method now() returns the epoch time in milliseconds, this method is used generally to find the time difference in milliseconds between the 2 timestamps  

const date = Date.now() 

console.log('Epoc time in milliseconds: ', date);
// Epoc time in milliseconds: 1736080469441

2. Static Date.parse()

parse() static method parses the input time and provides the corresponding epoch time, this is the same as using getTime() method to get epoch time for a given input date.

Date.parse("2025-01-07T11:45:51.966Z");
// 1736250351966

const date = new Date("2025-01-07T11:45:51.966Z");
date.getTime() 
// 1736250351966

3. getDate() & getTime()

const date = new Date("2025-01-07T11:45:51.966Z");

date.getDate() // 7
date.getTime() // 1736250351966

4. getDay(), getMonth() & getFullYear()

const date = new Date("2025-01-07T11:45:51.966Z");

date.getDay() // 2
date.getMonth() // 0
date.getFullYear() // 2025

5. getHours(), getMinutes(), getSeconds() & getMilliseconds()

const date = new Date("2025-01-07T11:45:51.966Z");

date.getHours(); // 17
date.getMinutes(); // 15
date.getSeconds(); // 51
date.getMilliseconds() // 966

Common use-cases of JavaScript Date Object in Frontend Interview

1. Find the time difference between 2 timestamps in javascript

static method Date.now() can be used to find the epoch time in milliseconds, and can be used to find the difference between 2 timestamps

Example

const epochTime1 = Date.now();
console.log('epochTime1 = ',epochTime1);

let sum = 0;
for(let i=0; i<1000000; i++){
  // do nothing
  sum = sum + i;
}

const epochTime2 = Date.now();
console.log('epochTime2 = ',epochTime2);

console.log('Time difference - ', epochTime2 - epochTime1);

// Output
epochTime1 = 1736081427953
epochTime2 = 1736081427962
Time difference -  9

Love this Blog? Share it Now!

Help others discover this resource

About the Author

Anuj Sharma

A seasoned Sr. Engineering Manager at GoDaddy (Ex-Dell) with over 12+ years of experience in the frontend technologies. A frontend tech enthusiast passionate building SaaS application to solve problem. Know more about me  🚀


Learn Next

Featured

20 Most Asked Custom Hooks in React for Interviews

Top 10 React Performance Optimization Techniques25 Top JavaScript Interview Questions for BeginnersHow to create custom useInfiniteScroll Hook in ReactImplement useThrottle Custom Hook In React

Comments

Be the first to share your thoughts!

Guest User

Please login to comment

0 characters


No comments yet.

Start the conversation!

About the Author

Anuj Sharma

A seasoned Sr. Engineering Manager at GoDaddy (Ex-Dell) with over 12+ years of experience in the frontend technologies. A frontend tech enthusiast passionate building SaaS application to solve problem. Know more about me  🚀

Share your expertise

Publish a blog or quick notes on topics you know well — your write-up could be the answer someone needs before their next frontend interview.

Build your portfolio

Help the community

Sharpen your skills

Earn goodies

Other Related Blogs

React Hook Rules: Why hooks declarations are not allowed inside functions

Frontendgeek

Last Updated Feb 6, 2026

A quick guide to explain an important react interview question, why React Hooks declarations are not allowed inside functions or any conditional blocks with code example.

Implementing a stopwatch using React - Frontend Machine Coding Question

Pallavi Gupta

Last Updated Feb 21, 2026

Concise explanation of stopwatch implementation using React, it involves the usage of useEffect hook for creating a stopwatch and tracking milliseconds.

Implement useClickOutside() custom Hook in React [Interview]

Anuj Sharma

Last Updated Dec 23, 2025

Understand the implementation of useClickOutside() custom hook in react and how it can be used to implement Modal like functionality.

Best Frontend System Design Interview Cheat Sheet 📒

Anuj Sharma

Last Updated Jun 9, 2026

A Comprehensive Frontend System Design Cheat Sheet helps you approach the Frontend System Design Interview in the most structured way and covers the 7 most important Frontend System Design Topics.

Stay Updated

Subscribe to FrontendGeek Hub for frontend interview preparation, interview experiences, curated resources and roadmaps.

FrontendGeek
FrontendGeek

All in One Preparation Hub to Ace Frontend Interviews. Master JavaScript, React, System Design, and more with curated resources.

Consider Supporting this Free Platform

Buy Me a Coffee

Product

HomeFrontend InterviewFrontend JobsQuestionsNewInterview ExperienceBlogsToolsLeaderboardFrontendGeek Chrome extensionGet the extension on the Chrome Web Store →

© 2026 FrontendGeek. All rights reserved