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
Parameter | Description |
---|---|
sec | This is the first parameter and required. You can pass values integer value from 0-59 in this parameter |
millisec | This 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:
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:
Conclusion
In this javascript tutorial, you have learned how to sets seconds with milliseconds parameters using setUTCSeconds method with an example.
You may like
- JavaScript: Date setUTCDate() Method
- Set UTC Month In javaScript
- setUTCFullYear() Method JavaScript With Examples
- javascript date setUTCHours() Method With Examples
- JavaScript: d.setUTCMinutes() Method e.g.
- JavaScript: Date.getUTCDate() Method
- getUTCmonth Method javaScript With Example
- javaScript Digital Clock with date
- JavaScript: Set Date Methods
- String Contains JavaScript | String includes() Method
- JavaScript Get Date Methods
- JavaScript Operators With Examples
- Sorting Using JavaScript Array Sort() Method
- JavaScript Replace String With Examples
- JavaScript Array splice() Method By Example
- JavaScript: Clone an Array & Object By Example
- 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.