API · JavaScript

JavaScript Date.toString() Method

The Date.toString() method converts a Date object to date and time and returns it as the string.

On this page

In JavaScript, the Date object is used to represent the Date and Time. We can declare this object with the new keyword.

The toString() method comes internally in JavaScript and represents an object in the string. The date.toString() method converts the Date object to date and time and represents it as a string.

Syntax of JavaScript date.toString() Method

date.toString()

Parameters

The date.toString() method doesn’t accept any parameter.

Return

A date and time string value are returned from the Date object.

Example Codes: Use the date.toString() Method

const date = new Date()
let dateString = date.toString()

console.log(dateString)

Output:

Thu Sep 8 2022 12:20:33 GMT+0600 (Bangladesh Standard Time)

The Date object has been declared in the date variable. We used the toString() method to represent date and time as a string.

This method returned the date and time as a string in the local time zone. To store the result, we declared a variable and printed the variable to see the result in the output.

Example Codes: Use the date.toString() Method Automatically

const date = new Date()
let dateString = `Today's Date and Time is ${new Date()}`

console.log(dateString)

Output:

Today's Date and Time is Thu Sep 8 2022 12:27:33 GMT+0600 (Bangladesh Standard Time)

The toString() method is automatically called when we have called the Date object inside a string.