此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Date.prototype.toUTCString()

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

toUTCString() 方法把一个日期转换为一个字符串,使用 UTC 时区。

尝试一下

const event = new Date("14 Jun 2017 00:00:00 PDT");

console.log(event.toUTCString());
// Expected output: "Wed, 14 Jun 2017 07:00:00 GMT"

语法

dateObj.toUTCString()

返回值

返回使用 UTC 时区表示给定日期的字符串

描述

toUTCString 的返回值是一个使用 UTC 时区的易读格式字符串。返回值的格式可能随平台而变化。通常返回值是一个 RFC-1123 格式的时间戳,这是一个 RFC-822 时间戳的小幅更新版。

示例

示例:使用toUTCString

var today = new Date();
var UTCstring = today.toUTCString();
// Mon, 03 Jul 2006 21:44:38 GMT

规范

规范
ECMAScript® 2027 Language Specification
# sec-date.prototype.toutcstring

浏览器兼容性

参见