JavaScript Date setUTCSeconds() method

The setUTCSeconds method in JavaScript is utilized to assign the seconds component for a designated date, using Coordinated Universal Time (UTC) as the reference.

Syntax

The syntax for the setUTCSeconds function is expressed as follows:

Example

dateObj.setUTCSeconds( secValue[, msValue]]])

Parameter

secValue - This denotes an integer ranging from 0 to 59, indicating the specific second. In cases where the supplied second value exceeds 59, the setUTCSeconds function will adjust the minute value accordingly.

msValue - This parameter is optional. It denotes an integer ranging from 0 to 999, which indicates the millisecond. Should the supplied millisecond value exceed 999, the setUTCSeconds function will adjust the second value accordingly.

JavaScript Date setUTCSeconds method example

In this section, we will explore the setUTCSeconds method by examining several examples.

Example 1

Let's examine an example that demonstrates how to display both the current and the modified value of seconds.

Example

<script>

var seconds=new Date();	

document.writeln("Current Second : "+seconds.getUTCSeconds()+"<br>");

seconds.setUTCSeconds(15);	

document.writeln("Updated Second : "+seconds.getUTCSeconds());

</script>

Output:

Output

Current Second : 46

Updated Second : 15

Example 2

Let’s examine an instance where we modify the second value of the specified time.

Example

<script>

var seconds=new Date("August 15, 1947 20:22:10 GMT+5:30");	

seconds.setUTCSeconds(15);

document.writeln("Updated Second : "+seconds.getUTCSeconds());

</script>

Output:

Output

Updated Second : 15

Example 3

In this illustration, we will define the millisecond value (exceeding 999) along with the seconds.

Example

<script>

var seconds=new Date("August 15, 1947 20:22:10");	

seconds.setUTCSeconds(10,1012);

document.writeln("Updated Second : "+seconds.getUTCSeconds());

</script>

Output:

Output

Updated Second : 11

Input Required

This code uses input(). Please provide values below: