JavaScript setSeconds 函数用于根据本地时间设置给定日期的秒和毫秒。setSeconds 函数的语法是:
Date.setSeconds(Seconds, Milliseconds)
在此 setSeconds 函数中,Millisecond 参数是可选的。你可以使用它,也可以省略它。在这里,我们使用 set Seconds 将当前日期的秒设置为 22。
<!DOCTYPE html>
<html>
<head>
<title> JS </title>
</head>
<body>
<h1> Example </h1>
<script>
var dt = Date();
document.write("Date and Time : " + dt + "<br/>");
dt.setSeconds(22);
document.write("After : " + dt);
</script>
</body>
</html>
Example
Date and Time: Thu Nov 08 2018 11:59:48 GMT+0530 (Indian Standard Time)
After : Thu Nov 08 2018 11:59:22 GMT+0530 (Indian Standard Time)
在此 JavaScript set Seconds 示例中,我们将自定义日期的秒设置为 55。
<!DOCTYPE html>
<html>
<head>
<title> JavaScriptSetSecondsFunctions </title>
</head>
<body>
<h1> Example </h1>
<script>
var dt = Date("January 1, 2017 10:11:22");
document.write("Date and Time : " + dt + "<br/>");
dt.setSeconds(55);
document.write("After setSeconds() : " + dt);
</script>
</body>
</html>
