getUTCSeconds 方法

返回 Date 对象中用全球标准时间 (UTC)表示的秒钟值。

dateObj.getUTCSeconds()

必选项 dateObj 参数为 Date 对象。

说明

要获得用本地时间表示的秒钟数,请使用 getSeconds 方法。

getUTCSeconds 方法返回一个处于 0 到 59 之间的整数,这个整数表示相应的 Date 对象中的秒钟数。在下面两种情况下返回值为 0:在当前的一分钟中所经过的时间短于 1 秒钟,或者在创建 Date 对象的时候没有将时间保存到该对象中。而为了确定究竟属于哪种情况,唯一的方法就是同时检查分钟和小时值是否为 0。如果这两个值也都是 0,那么几乎可以确定是没有将时间保存到 Date 对象中。

示例

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

function UTCTimeDemo(){
   var d, s = "当前 UTC 时间为: ";
   var c = ":";
   d = new Date();
   s += d.getUTCHours() + c;
   s += d.getUTCMinutes() + c;
   s += d.getUTCSeconds() + c;
   s += d.getUTCMilliseconds();
   return(s);
}

要求

版本 3

请参阅

Date 对象的方法 | getSeconds 方法 | setSeconds 方法 | setUTCSeconds 方法

应用于: Date 对象