JavaScript Date toString() 方法

定义和用法

toString() 方法将 Date 对象转换为字符串。

注释:每当需要将 Date 对象显示为字符串时,JavaScript 就会自动调用此方法。

实例

将 Date 对象转换为字符串:

var d = new Date();
var n = d.toString();

亲自试一试

语法

Date.toString()

Parameters

No parameters.

Technical details

Return value: String representing date and time in string format.
JavaScript version: ECMAScript 1

Browser support

Method Chrome IE Firefox Safari Opera
toString() Support Support Support Support Support

Related pages

Tutorial:JavaScript date

Tutorial:JavaScript date format

Tutorial:JavaScript string