搜索吧

首页 » 搜成宝库 » 常用知识 » JavaScript toUTCString()和JavaScript toGMTString() 方法
xiaoyaoyou - 2009-11-17 15:58:53
JavaScript toUTCString() 方法
返回一个已被转换为字符串的,用全球标准时间 (UTC)表示的日期。

dateObj.toUTCString()

必选项 dateObj 参数为任意 Date 对象。

说明
toUTCString 方法返回一个 String 对象,此对象中包含了使用 UTC 惯例以一种方便易读的形式进行格式化的日期。

示例
下面这个例子说明了 toUTCString 方法的用法。

function toUTCStrDemo(){
  var d, s;                  // 声明变量。
  d = new Date();            // 创建 Date 对象。
  s = "Current setting is ";
  s += d.toUTCString();      // 转换为 UTC 字符串。
  return(s);                  // 返回 UTC 字符串。
}

///////////////////////////////////////////////////////////////////////////////////
JavaScript toGMTString() 方法
定义和用法
toGMTString() 方法可根据格林威治时间 (GMT) 把 Date 对象转换为字符串,并返回结果。

语法
dateObject.toGMTString()返回值
dateObject 的字符串表示。此日期会在转换为字符串之前由本地时区转换为 GMT 时区。
提示和注释
不赞成使用此方法。请使用 toUTCString() 取而代之!!
1
查看完整版本: JavaScript toUTCString()和JavaScript toGMTString() 方法