JavaScript Date toDateString() method - JavaScript Tutorial

JavaScript Date toDateString() method

BLUF: This tutorial on JavaScript Date toDateString() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date toDateString() method

Understanding JavaScript Date toDateString() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The toDateString method in JavaScript is utilized to extract the date component from a Date object and presents it as a string.

Syntax

The syntax for the toDateString method is expressed as follows:

Example

dateObj.toDateString()

Return

A string that denotes the date segment of a Date object.

JavaScript Date toDateString method example

In this section, we will explore the toDateString method by examining several illustrative examples.

Example 1

Let’s examine an instance of retrieving the current date formatted as a string.

Example

<script>

var date=new Date();

document.writeln(date.toDateString());

</script>

Output:

Output

Tue Aug 07 2018

Example 2

Let’s examine an example that retrieves only the date component from a given Date object.

Example

<script>

var date=new Date("August 15, 1947 20:22:10 GMT+0530 (India Standard Time) ");

document.writeln(date.toDateString());

</script>

Output:

Output

Fri Aug 15 1947

Example 3

Let’s examine another example that retrieves only the date component from a given Date object.

Example

<script>

var date=new Date(1947, 7, 15, 20, 22, 10);

document.writeln(date.toDateString());

</script>

Output:

Output

Fri Aug 15 1947

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience