JavaScript 的 Date 对象中的 getUTCSeconds 方法用于根据世界时 (UTC) 返回表示时间的秒数。
getUTCSeconds() 方法用于根据世界时 (UTC) 返回表示时间的秒数。
dateObject.getUTCSeconds();
参数 | 描述 |
---|---|
dateObject | 要获取的日期。 |
类型 | 描述 |
---|---|
Number | 返回它的秒字段,该值是一个 0 ~ 59 之间的整数。 |
该函数只支持 JavaScript 1.3 即以上版本。
该函数支持所有的主流浏览器。
使用 getUTCSeconds 获取时间的秒数
<!DOCTYPE html>
<html>
<head>
<title>JavaScript getUTCSeconds</title>
<script type="text/javascript">
console.log("嗨客网(www.haicoder.net)");
var date = new Date("2022/07/11 17:50:09:110");
var utcSeconds = date.getUTCSeconds();
console.log("date =", date, "utcSeconds =", utcSeconds);
var date2 = new Date("2022/11/13 20:50:19:109");
var utcSeconds2 = date2.getUTCSeconds();
console.log("date2 =", date2, "utcSeconds2 =", utcSeconds2);
</script>
</head>
</html>
程序运行后,控制台输出如下:
我们分别创建了两个 Date 对象,即 date1 和 date2,接着,我们使用 date 对象的 getUTCSeconds 方法分别获取了两个对象的日期的秒数。
JavaScript 的 Date 对象中的 getUTCSeconds 方法用于根据世界时 (UTC) 返回表示时间的秒数。JavaScript getUTCSeconds 语法:
dateObject.getUTCSeconds();