How to Convert Date to String in JavaScript

To convertdate to a string in JavaScript, you can use the “toString()” function. The toString() is a built-in method that converts the date objects into a string. JavaScript uses the function internally when an object must be displayed as text (like in HTML) or used as a string.




By default, there is no necessary parameter that needs to be passed.

  1. If no parameter is passed, it will return the current date and time as a string.
  2. If the parameter is passed in any format other than string data types, the JavaScript will return the date in string format for that date entered by the user.

Return value

It is a Date and time in the form of a string.

Example 1

let dateObj = new Date();
let text = dateObj.toString();


Sat Mar 19 2022 12:19:24 GMT+0530 (India Standard Time)
  1. In the above code, we first defined a variable called “d” a user-defined variable using var.
  2. Then we initialized the JavaScript object using the new Date() method. 
  3. We then defined another variable called “text”.
  4. We stored the date value in the form of a string and then stored the value in the “text” variable. Finally, we printed the output on the screen with the help of the console.log() method. The toString() method here converts the data types of the date into the String data types.

Example 2

The toString() function does not take any parameter, but we apply the toString() function to the date object, and the date object can be created using the new Date() function, and it can take multiple parameters.

const date = new Date(2022, 2);
let text = date.toString();


Tue Mar 01 2022 00:00:00 GMT+0530 (India Standard Time)

Example 3

const date = new Date(2022, 2, 19);
let text = date.toString();


Sat Mar 19 2022 00:00:00 GMT+0530 (India Standard Time)

That’s it.

Leave a Comment