Javascript - Date toString() Method

The toString() method converts a Date object to a string.

Description

The toString() method converts a Date object to a string.

This method is called by JavaScript when converting a Date object to a string.

Syntax

Date.toString()

Parameters

None

Return

A String, representing the date and time as a string

Example

Convert a Date object to a string:

Demo

//display the date and time as a string.

var d = new Date();
var n = d.toString();
console.log(n);/*from w ww  .java  2s  .  c  o  m*/
console.log(d);

Result