JavaScript setUTCSecond() Method

JavaScript set utc seconds with millisecond; Through this tutorial, i am going to share with you how to sets utc seconds with milliseconds using the javaScript setUTCSeconds() method.

JavaScript setUTCSeconds() Method

The setUTCSeconds() is an inbuild javascript method, which is used to sets the seconds of a date object, according to the universal time (UTC).

Note: This method accepts two-parameter values. The first one is required and the remaining parameters are optional in this function.

Syntax of JavaScript setUTCSeconds() Method

Date.setUTCSeconds(sec, millisec);

Parameter of JavaScript setUTCSeconds() Method

ParameterDescription
secThis is the first parameter and required. You can pass values integer value from 0-59 in this parameter
millisecThis is a second parameter and optional. You can pass values integer value from 0-999 in this parameter

Example 1 – JavaScript setUTCSeconds() Method

See the following example of setUTCSeconds method; as shown below:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>javascript date set utc seconds</title>
</head>
<body>
  <script type = "text/javascript">
     var date = new Date();
     date.setUTCSeconds(16);
     document.write( "javascript date set utc seconds using setUTCSeconds() : " + date );
  </script>  
</body>
</html>

Output of the above code is:-

javascript date set utc seconds

Example 2 – JavaScript setUTCSeconds() Method

Let’s take an second example using setUTCSeconds method; as shown below:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>javascript date set utc seconds with milliseconds</title>
</head>
<body>
  <script type = "text/javascript">
     var date = new Date();
     date.setUTCSeconds(16, 50);
     document.write( "javascript date set utc seconds with milliseconds using setUTCSeconds() : " + date );
  </script>  
</body>
</html>

Output of the above code is:-

javascript date set utc seconds with milliseconds

Conclusion

In this javascript tutorial, you have learned how to sets seconds with milliseconds parameters using setUTCSeconds method with an example.

Recommended JavaScript Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.