.toString()

Converts a Date object to a string.

Syntax

myDate.toString();

Example 1

Print the Date object as a string:

const currentDate = new Date('July 15, 2021 11:48:57');
console.log(typeof currentDate);
// Output: object
const currentDateString = currentDate.toString();
console.log(typeof currentDateString);
// Output: string
console.log(currentDateString);
// Output: Thu Jul 15 2021 11:48:57 GMT-0700 (Pacific Daylight Time)
// Note: Timezone may vary
Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn JavaScript on Codecademy

Edit this page on GitHub

Contributors