首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

date.toDateString

toDateString()?方法以美式英语和人类易读的形式返回一个日期对象日期部分的字符串。

语法

代码语言:javascript
复制
dateObj.toDateString()

返回值

以美式英语和人类易读的形式返回一个日期对象日期部分的字符串。

描述

Date对象实例引用一个具体的时间点。调用toString方法会以美式英语和人类易读的形式返回日期对象的格式化字符串。在?SpiderMonkey?里,该字符串由日期部分(年月日)和其后的时间部分(时分秒及时区)组成。有时需要获取日期部分的字符串,这可以由?toDateString方法完成。

toDateString()方法特别有用,因为实现ECMA-262的兼容引擎可能在从toString()获得的字符串中不同,因为格式是依赖于实现的,而简单的字符串分割方法可能不会在多个引擎之间产生一致的结果。

例子

A basic usage of toDateString()

代码语言:javascript
复制
var d = new Date(1993, 6, 28, 14, 39, 7);

console.log(d.toString());     // logs Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
console.log(d.toDateString()); // logs Wed Jul 28 1993

规格

Specification

Status

Comment

ECMAScript 3rd Edition (ECMA-262)

Standard

Initial definition.

ECMAScript 5.1 (ECMA-262)The definition of 'Date.prototype.toDateString' in that specification.

Standard

?

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Date.prototype.toDateString' in that specification.

Standard

?

ECMAScript Latest Draft (ECMA-262)The definition of 'Date.prototype.toDateString' in that specification.

Living Standard

?

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com