setUTCSecond() Method By JavaScript

setUTCSecond() Method By JavaScript

javascript set utc seconds with millisecond example. Here we will explain, how to sets utc seconds with milliseconds using the javaScript setUTCSeconds() method.

Some time, we work with date and time methods or function in javaScript. We need to set or get the utc time in hours, minutes, seconds and milliseconds. So this tutorial help you for sets the seconds in javascript with milliseconds.

JavaScript: setUTCSeconds() Method

Definition:- 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

Date.setUTCSeconds(sec, millisec);

Parameter of 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

If you want to pass the following

1. seconds in setUTCSeconds() method:

 Date.setUTCSeconds(second)

2. seconds and millisecond in setUTCSeconds() method:

 Date.setUTCSeconds(second, millisecond)

Example -1

Here we will take first example of setUTCSeconds method, without passing milliseconds:

<!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>

Result of example – 1 is:

javascript date set utc seconds

Example – 2

Here we will take second example of setUTCSeconds method, with seconds and milliseconds is:

<!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>

Result of example – 2 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.

You may like

  1. JavaScript: Date setUTCDate() Method
  2. Set UTC Month In javaScript
  3. setUTCFullYear() Method JavaScript With Examples
  4. javascript date setUTCHours() Method With Examples
  5. JavaScript: d.setUTCMinutes() Method e.g.
  6. JavaScript: Date.getUTCDate() Method
  7. getUTCmonth Method javaScript With Example
  8. javaScript Digital Clock with date
  9. JavaScript: Set Date Methods
  10. String Contains JavaScript | String includes() Method
  11. JavaScript Get Date Methods
  12. JavaScript Operators With Examples
  13. Sorting Using JavaScript Array Sort() Method
  14. JavaScript Replace String With Examples
  15. JavaScript Array splice() Method By Example
  16. JavaScript: Clone an Array & Object By Example
  17. Check the Object is Array or not in javascript

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *