JavaScript .toString()

Anonymous contributor's avatar
Anonymous contributor
Published Jul 22, 2021Updated May 31, 2023
Contribute to Docs

Converts a Date object to a string.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

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

Codebyte Example

The following is runnable, and demonstrates the use of the .toString() method.

Code
Output

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours