Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript setSeconds() Method

JavaScript setSeconds() Method

Date Object Reference JavaScript Date object

Example

Set the seconds field of the current time to 35:

var d = new Date();

d.setSeconds(35);

d Output result:

Try it »


Definition and Usage

The setSeconds() method is used to set the seconds field of a date object.

This method can be used to set the milliseconds.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setSeconds() method.


Syntax

Date

.setSeconds(

sec

,

millisec

)

Parameter value

Parameters Description
sec Required. A value representing the seconds.

This value is an integer between 0 and 59:

  • -1 is the last second of the previous minute.
  • 60 is the first second of the next minute.
  • | | *millisec* | Optional. A value representing the milliseconds.

    between 0 and 999. This parameter was not supported before ECMAScript standardization:

    |

    Return Value

    Type Description
    Number Milliseconds from January 1, 1970 to the adjusted date. Before ECMAScript standardization, this method returned nothing.

    Technical Details

    JavaScript version: 1.0

    More examples

    Example

    Set the seconds and milliseconds:

    var d = new Date();

    d.setSeconds(35,825);

    var n=d.getSeconds() + ":" + d.getMilliseconds();

    n Output result:

    Try it »


    Date Object Reference JavaScript Date object