JavaScript setMinutes 函数

JavaScript setMinutes 函数用于根据本地时间设置给定日期的分钟、秒和毫秒。setMinutes 函数的语法是

 Date.setMinutes(Minutes, Seconds, Milliseconds)

在此 set Minutes 函数中,Seconds 和 Milliseconds 参数是可选的。在这里,我们使用 setMinutes 将当前日期的分钟设置为 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.setMinutes(22);
  document.write("After : " + dt);
</script>
</body>
</html>
Example

Date and Time: Thu Nov 08 2018 11:58:36 GMT+0530 (Indian Standard Time)
After : Thu Nov 08 2018 11:22:36 GMT+0530 (Indian Standard Time)

在此 setMinutes 函数示例中,我们将自定义日期的分钟设置为 22。

<!DOCTYPE html>
<html>
<head>
    <title> JavaScriptSetMinutesFunctions </title>
</head>
<body>
    <h1> JavaScriptsetMinutesFunctionExample </h1>
<script>
  var dt = Date("January 1, 2017 10:11:22");
  document.write("Date and Time : " + dt + "<br/>")

  dt.setMinutes(22);
  document.write("After setMinutes() : " + dt);
</script>
</body>
</html>
setMinutes Function Example

在此 JavaScript 示例中,我们将分钟设置为 45,将秒设置为 05。

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date("January 1, 2017 10:11:22");
  document.write("Date and Time : " + dt + "<br/>");

  dt.setMinutes(45, 05);
  document.write("After : " + dt);
</script>
</body>
</html>
Example

Date and Time: Sun Jan 01 2017 10:11:22 GMT+0530 (Indian Standard Time)
After : Sun Jan 01 2017 10:45:05 GMT+0530 (Indian Standard Time)