JavaScript setUTCSeconds

JavaScript setUTCSeconds function is used to set the Seconds and Milliseconds of a specified date as per the universal time. The syntax of the JavaScript setUTCSeconds function is:

 Date.setUTCSeconds(Seconds, Milliseconds)

JavaScript setUTCSeconds Function Example

For this Date Function Milliseconds is an optional argument.. We are using setUTCSeconds to set the current date seconds to 49 as per the universal time.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Set UTC Seconds Functions </title>
</head>
<body>
    <h1> JavaScript setUTCSeconds Function Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt + "<br/>");

  dt.setUTCSeconds(49);
  document.write("After setUTCSeconds() : " + dt);
</script>
</body>
</html>
JavaScript setUTCSeconds Example

Date and Time: Thu Nov 08 2018 12:13:07 GMT+0530 (Indian Standard Time)
After setUTCSeconds(): Thu Nov 08 2018 12:13:49 GMT+0530 (Indian Standard Time)

JavaScript set UTC Seconds Function Example 2

In this JavaScript set UTC Seconds example, we set the custom date seconds to 55 according to universal time.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Set UTC Seconds Functions </title>
</head>
<body>
    <h1> JavaScript setUTCSeconds Function Example </h1>
<script>
  var dt = Date("May 1, 2016 10:11:19");
  document.write("Date and Time : " + dt + "<br/>");

  dt.setUTCSeconds(55);
  document.write("After setUTCSeconds() : " + dt);
</script>
</body>
</html>
JavaScript setUTCSeconds 2