JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JS Date Formats


📘 JavaScript Date Formats – Representing and Parsing Dates

JavaScript allows different ways to format and parse date strings. However, the most reliable and consistent format is the ISO 8601 format.

When you pass a date string to new Date(), JavaScript interprets it based on format and locale.


🔹 Common Date Formats in JavaScript

Format Type Format Example Description
ISO Format "2025-07-10" or "2025-07-10T14:30:00Z" International standard (YYYY-MM-DD)
Short Date "07/10/2025" (MM/DD/YYYY) Locale-based (may vary by region)
Long Date "July 10, 2025" Full month name with day and year
Full ISO new Date().toISOString() Returns full date in ISO format

🔹 Creating Dates Using Formats

new Date("2025-07-10");           // ISO format (safe)
new Date("07/10/2025");           // MM/DD/YYYY (region dependent)
new Date("July 10, 2025");        // Long date (safe for most locales)

🟡 Warning: Avoid ambiguous formats like "10/07/2025" — JavaScript may misinterpret them depending on browser/locale.


🔹 Formatting Dates with Methods

Method Description Example
toDateString() "Thu Jul 10 2025" Human-readable format
toLocaleDateString() "7/10/2025" (based on your locale) Locale-aware format
toISOString() "2025-07-10T00:00:00.000Z" ISO 8601 format
toUTCString() "Thu, 10 Jul 2025 00:00:00 GMT" UTC time string

🔹 Example

let date = new Date("2025-07-10");

console.log(date.toDateString());        // "Thu Jul 10 2025"
console.log(date.toLocaleDateString());  // "7/10/2025" (varies by region)
console.log(date.toISOString());         // "2025-07-10T00:00:00.000Z"

Practice Questions

Q1. Which date format should be used to avoid parsing errors across all browsers?

Q2. What will new Date("2025-07-10").toDateString() return?

Q3. How do you display the current date in ISO format using a built-in method?

Q4. How do you show a date in your local format using JavaScript?

Q5. What format is "2025-07-10T00:00:00.000Z" an example of?

Q6. How do you safely create a date object for July 10, 2025, using a string?

Q7. Which format can be misinterpreted due to locale differences: "07/10/2025" or "2025-07-10"?

Q8. What does toUTCString() return when called on a date object?

Q9. How do you format a date as "Thu Jul 10 2025" using a method?

Q10. How can you create a readable long date like "July 10, 2025"?


JS Date Formats Quiz

Q1: Which format is considered the most reliable for creating dates in JavaScript?

A. "07/10/2025"
B. "10/07/2025"
C. "July 10, 2025"
D. "2025-07-10"

Q2: What does toISOString() return?

A. Date object
B. Local time string
C. ISO-formatted string
D. Locale date string

Q3: What is the output of new Date("2025-07-10").toDateString()?

A. "Thu Jul 10 2025"
B. "07/10/2025"
C. "10/07/2025"
D. "July 10, 2025"

Q4: Which of the following is affected by the user's location settings?

A. toISOString()
B. toLocaleDateString()
C. toUTCString()
D. toDateString()

Q5: Which method returns something like "Thu, 10 Jul 2025 00:00:00 GMT"?

A. toDateString()
B. toUTCString()
C. toISOString()
D. toLocaleString()

Q6: Which format might be interpreted differently across regions?

A. "2025-07-10"
B. "July 10, 2025"
C. "07/10/2025"
D. "2025/07/10"

Q7: What is the result of new Date("July 10, 2025")?

A. Error
B. "2025-07-10T00:00:00.000Z"
C. A valid date object
D. Undefined

Q8: What does toLocaleDateString() return?

A. ISO format
B. UTC format
C. Localized date string
D. Raw Date object

Q9: Which method gives the ISO 8601 representation of a date?

A. getDate()
B. toISOString()
C. formatDate()
D. toLocalISO()

Q10: Which method is best for showing a date in readable English like "Thu Jul 10 2025"?

A. toString()
B. toDateString()
C. toLocaleString()
D. toTimeString()

Go Back Top